use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class GeneratorFunctionConstructor method CreateDynamicGenerator.
private static OrdinaryGenerator CreateDynamicGenerator(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
/* step 1 (not applicable) */
/* step 2 (not applicable) */
/* step 3 */
Intrinsics fallbackProto = Intrinsics.Generator;
/* steps 4-10 */
String[] sourceText = functionSourceText(cx, args);
String parameters = sourceText[0], bodyText = sourceText[1];
/* steps 11, 13-20 */
Source source = functionSource(SourceKind.Generator, cx.getRealm(), callerContext);
RuntimeInfo.Function function;
try {
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
function = scriptLoader.generator(source, parameters, bodyText).getFunction();
} catch (ParserException | CompilationException e) {
throw e.toScriptException(cx);
}
/* step 12 */
boolean strict = function.isStrict();
/* steps 21-22 */
ScriptObject proto = GetPrototypeFromConstructor(cx, newTarget, fallbackProto);
/* step 23 */
OrdinaryGenerator f = OrdinaryGenerator.FunctionAllocate(cx, proto, strict, FunctionKind.Normal);
/* steps 24-25 */
LexicalEnvironment<GlobalEnvironmentRecord> scope = f.getRealm().getGlobalEnv();
/* step 26 */
FunctionInitialize(f, FunctionKind.Normal, function, scope, newFunctionExecutable(source));
/* step 27 */
OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
f.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
/* step 28 (not applicable) */
/* step 29 */
SetFunctionName(f, "anonymous");
/* step 30 */
return f;
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class WrapperProxy method get.
@Override
public Object get(ExecutionContext cx, long propertyKey, Object receiver) {
/* modified 9.1.8 [[Get]] (P, Receiver) */
Property desc = proxyTarget.getOwnProperty(cx, propertyKey);
if (desc == null) {
// modified
ScriptObject parent = getPrototype();
if (parent == null) {
return UNDEFINED;
}
return parent.get(cx, propertyKey, receiver);
}
if (desc.isDataDescriptor()) {
return desc.getValue();
}
assert desc.isAccessorDescriptor();
Callable getter = desc.getGetter();
if (getter == null) {
return UNDEFINED;
}
return getter.call(cx, receiver);
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class WrapperProxy method set.
@Override
public boolean set(ExecutionContext cx, Symbol propertyKey, Object value, Object receiver) {
/* modified 9.1.9 [[Set] (P, V, Receiver) */
Property ownDesc = proxyTarget.getOwnProperty(cx, propertyKey);
if (ownDesc == null) {
// modified
ScriptObject parent = getPrototype();
if (parent != null) {
return parent.set(cx, propertyKey, value, receiver);
} else {
ownDesc = new Property(UNDEFINED, true, true, true);
}
}
if (ownDesc.isDataDescriptor()) {
if (!ownDesc.isWritable()) {
return false;
}
if (!Type.isObject(receiver)) {
return false;
}
ScriptObject _receiver = Type.objectValue(receiver);
Property existingDescriptor = _receiver.getOwnProperty(cx, propertyKey);
if (existingDescriptor != null) {
PropertyDescriptor valueDesc = new PropertyDescriptor(value);
return _receiver.defineOwnProperty(cx, propertyKey, valueDesc);
} else {
return CreateDataProperty(cx, _receiver, propertyKey, value);
}
}
assert ownDesc.isAccessorDescriptor();
Callable setter = ownDesc.getSetter();
if (setter == null) {
return false;
}
setter.call(cx, receiver, value);
return true;
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class AsyncGeneratorFunctionConstructor method CreateDynamicFunction.
/**
* 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)
*
* @param callerContext
* the caller execution context
* @param cx
* the execution context
* @param newTarget
* the newTarget constructor function
* @param args
* the function arguments
* @return the new async generator function object
*/
private static FunctionObject CreateDynamicFunction(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
/* step 1 (not applicable) */
/* step 2 (not applicable) */
/* step 3 */
Intrinsics fallbackProto = Intrinsics.AsyncGenerator;
/* steps 4-10 */
String[] sourceText = functionSourceText(cx, args);
String parameters = sourceText[0], bodyText = sourceText[1];
/* steps 11, 13-20 */
Source source = functionSource(SourceKind.AsyncGenerator, cx.getRealm(), callerContext);
RuntimeInfo.Function function;
try {
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
function = scriptLoader.asyncGenerator(source, parameters, bodyText).getFunction();
} catch (ParserException | CompilationException e) {
throw e.toScriptException(cx);
}
/* step 12 */
boolean strict = function.isStrict();
/* steps 21-22 */
ScriptObject proto = GetPrototypeFromConstructor(cx, newTarget, fallbackProto);
/* step 23 */
OrdinaryAsyncGenerator f = FunctionAllocate(cx, proto, strict, FunctionKind.Normal);
/* steps 24-25 */
LexicalEnvironment<GlobalEnvironmentRecord> scope = f.getRealm().getGlobalEnv();
/* step 26 */
FunctionInitialize(f, FunctionKind.Normal, function, scope, newFunctionExecutable(source));
/* step 27 */
OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.AsyncGeneratorPrototype);
f.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
/* step 28 (not applicable) */
/* step 29 */
SetFunctionName(f, "anonymous");
/* step 30 */
return f;
}
use of com.github.anba.es6draft.runtime.types.Property in project es6draft by anba.
the class OrdinaryFunction method MakeConstructor.
/**
* 9.2.8 MakeConstructor (F, writablePrototype, prototype)
*
* @param <CONSTRUCTOR>
* the constructor function type
* @param cx
* the execution context
* @param f
* the function object
*/
public static <CONSTRUCTOR extends FunctionObject & Constructor> void MakeConstructor(ExecutionContext cx, CONSTRUCTOR f) {
/* step 3 */
assert f.isExtensible() && !f.ordinaryHasOwnProperty("prototype");
/* step 4 */
boolean writablePrototype = true;
/* step 5.a */
OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.ObjectPrototype);
/* step 5.b-c */
prototype.infallibleDefineOwnProperty("constructor", new Property(f, writablePrototype, false, true));
/* steps 6-7 */
f.infallibleDefineOwnProperty("prototype", new Property(prototype, writablePrototype, false, false));
/* step 8 (return) */
}
Aggregations