use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class SharedArrayBufferConstructor method construct.
/**
* SharedArrayBuffer(length)
*/
@Override
public SharedArrayBufferObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object length = argument(args, 0);
/* step 1 (not applicable) */
/* step 2 */
double numberLength = ToNumber(calleeContext, length);
/* steps 3-4 */
long byteLength = ToLength(numberLength);
/* step 5 */
if (numberLength != byteLength) {
// SameValueZero
throw newRangeError(calleeContext, Messages.Key.InvalidBufferSize);
}
/* step 6 */
return AllocateSharedArrayBuffer(calleeContext, newTarget, byteLength);
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class ScriptEngineImpl method invoke.
private Object invoke(ScriptObject thisValue, String name, Object... args) throws javax.script.ScriptException, NoSuchMethodException {
Realm realm = getEvalRealm(context);
RuntimeContext runtimeContext = realm.getWorld().getContext();
Console console = runtimeContext.getConsole();
runtimeContext.setConsole(new ScriptingConsole(context));
try {
Object[] arguments = TypeConverter.fromJava(args);
if (thisValue == null) {
thisValue = realm.getGlobalThis();
}
ExecutionContext cx = realm.defaultContext();
Object func = thisValue.get(cx, name, thisValue);
if (!IsCallable(func)) {
throw new NoSuchMethodException(name);
}
Object result = ((Callable) func).call(cx, thisValue, arguments);
realm.getWorld().runEventLoop();
return TypeConverter.toJava(result);
} catch (ScriptException e) {
throw new javax.script.ScriptException(e);
} finally {
runtimeContext.setConsole(console);
}
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class ScriptEngineImpl method eval.
Object eval(Script script, ScriptContext context) throws javax.script.ScriptException {
Realm realm = getEvalRealm(context);
RuntimeContext runtimeContext = realm.getWorld().getContext();
Console console = runtimeContext.getConsole();
runtimeContext.setConsole(new ScriptingConsole(context));
try {
// Prepare a new execution context before calling the generated code.
ExecutionContext evalCxt = newScriptingExecutionContext(realm, script, new LexicalEnvironment<>(realm.getGlobalEnv(), new ScriptContextEnvironmentRecord(realm.defaultContext(), context)));
Object result = script.evaluate(evalCxt);
realm.getWorld().runEventLoop();
return TypeConverter.toJava(result);
} catch (ScriptException e) {
throw new javax.script.ScriptException(e);
} finally {
runtimeContext.setConsole(console);
}
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class Uint8x16Constructor method call.
@Override
public Object call(ExecutionContext callerContext, Object thisValue, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object[] fields = new Object[VECTOR_LENGTH];
for (int i = 0; i < VECTOR_LENGTH; ++i) {
fields[i] = i < args.length ? args[i] : UNDEFINED;
}
return SIMDCreateInt(calleeContext, SIMD_TYPE, fields, AbstractOperations::ToUint8);
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class RegExpConstructor method construct.
/**
* 21.2.3.1 RegExp ( pattern, flags )
*/
@Override
public RegExpObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object pattern = argument(args, 0);
Object flags = argument(args, 1);
/* steps 1-2 */
boolean patternIsRegExp = IsRegExp(calleeContext, pattern);
/* steps 5-10 */
return RegExpCreate(calleeContext, newTarget, pattern, flags, patternIsRegExp);
}
Aggregations