use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class NativeErrorConstructor method construct.
/**
* 19.5.6.1.1 NativeError (message)
* <p>
* <strong>Extension</strong>: NativeError (message, fileName, lineNumber, columnNumber)
*/
@Override
public ErrorObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object message = argument(args, 0);
/* step 1 (not applicable) */
/* step 2 */
ErrorObject obj = OrdinaryCreateFromConstructor(calleeContext, newTarget, type.prototype(), ErrorObject::new);
/* step 3 */
if (!Type.isUndefined(message)) {
CharSequence msg = ToString(calleeContext, message);
obj.defineErrorProperty("message", msg, false);
}
/* extension: fileName, lineNumber and columnNumber arguments */
if (args.length > 1) {
CharSequence fileName = ToString(calleeContext, args[1]);
obj.defineErrorProperty("fileName", fileName, true);
}
if (args.length > 2) {
int line = ToInt32(calleeContext, args[2]);
obj.defineErrorProperty("lineNumber", line, true);
}
if (args.length > 3) {
int column = ToInt32(calleeContext, args[3]);
obj.defineErrorProperty("columnNumber", column, true);
}
/* step 4 */
return obj;
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class ObjectConstructor method call.
/**
* 19.1.1.1 Object ( [ value ] )
*/
@Override
public ScriptObject call(ExecutionContext callerContext, Object thisValue, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object value = argument(args, 0);
/* step 2 */
if (Type.isUndefinedOrNull(value)) {
return ObjectCreate(calleeContext, Intrinsics.ObjectPrototype);
}
/* step 3 */
return ToObject(calleeContext, value);
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class BooleanConstructor method construct.
/**
* 19.3.1.1 Boolean (value)
*/
@Override
public BooleanObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
/* step 1 */
boolean b = args.length > 0 && ToBoolean(args[0]);
/* steps 3-5 */
return BooleanCreate(calleeContext, b, GetPrototypeFromConstructor(calleeContext, newTarget, Intrinsics.BooleanPrototype));
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class SymbolConstructor method call.
/**
* 19.4.1.1 Symbol ( [ description ] )
*/
@Override
public Symbol call(ExecutionContext callerContext, Object thisValue, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object description = argument(args, 0);
/* step 1 (not applicable) */
/* steps 2-3 */
String descString = Type.isUndefined(description) ? null : ToFlatString(calleeContext, description);
/* step 4 */
return new Symbol(descString);
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class PromiseConstructor method construct.
/**
* 25.4.3.1 Promise ( executor )
*/
@Override
public PromiseObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object executor = argument(args, 0);
/* step 2 */
if (!IsCallable(executor)) {
throw newTypeError(calleeContext, Messages.Key.NotCallable);
}
/* steps 3-7 */
PromiseObject promise = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.PromisePrototype, GetPromiseAllocator(calleeContext.getRealm()));
/* step 8 */
ResolvingFunctions resolvingFunctions = CreateResolvingFunctions(calleeContext, promise);
/* steps 9-10 */
try {
/* step 9 */
((Callable) executor).call(calleeContext, UNDEFINED, resolvingFunctions.getResolve(), resolvingFunctions.getReject());
} catch (ScriptException e) {
/* step 10 */
resolvingFunctions.getReject().call(calleeContext, UNDEFINED, e.getValue());
}
/* step 11 */
return promise;
}
Aggregations