use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class Properties method createExternalValues.
private static <OWNER> void createExternalValues(ExecutionContext cx, ScriptObject target, OWNER owner, ObjectLayout layout, Converter converter) {
for (Entry<Value, Object> entry : layout.values.entrySet()) {
Value val = entry.getKey();
assert entry.getValue() instanceof MethodHandle;
Object value = resolveValue(cx, converter, (MethodHandle) entry.getValue(), owner);
defineProperty(cx, target, val.name(), val.symbol(), val.attributes(), value);
}
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class WrapperProxy method hasProperty.
@Override
public boolean hasProperty(ExecutionContext cx, Symbol propertyKey) {
/* modified 9.1.7 [[HasProperty]](P) */
boolean hasOwn = HasOwnProperty(cx, proxyTarget, propertyKey);
if (hasOwn) {
return true;
}
// modified
ScriptObject parent = getPrototype();
if (parent != null) {
return parent.hasProperty(cx, propertyKey);
}
return false;
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class NodeModuleRecord method instantiate.
@Override
public void instantiate() {
assert realm != null : "module is not linked";
if (environment == null) {
ScriptObject exports = getModuleExportsOrEmpty();
environment = newObjectEnvironment(exports, realm.getGlobalEnv());
// Compile the module.
ExecutionContext cx = realm.defaultContext();
Object compile = Get(cx, moduleObject, "compile");
Callable moduleFn = CreateDynamicFunction(cx, source, function.getFunction());
Callable requireFn = NodeFunctions.createRequireFunction(this);
Call(cx, compile, moduleObject, moduleFn, requireFn);
// Create the module bindings.
ScriptObject currentExports = getModuleExportsOrEmpty();
if (currentExports != exports) {
// Module exports property has changed, update environment with new bindings.
environment = newObjectEnvironment(currentExports, realm.getGlobalEnv());
}
exportedNames = ownNames(currentExports);
instantiated = true;
}
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class ShellFunctions method evalScript.
/**
* shell-function: {@code evalScript(sourceString, [options])}
*
* @param cx
* the execution context
* @param sourceString
* the source string
* @param options
* the options object (optional)
* @return the evaluation result
*/
@Function(name = "evalScript", arity = 1)
public Object evalScript(ExecutionContext cx, String sourceString, Object options) {
String name = "";
int line = 1;
Realm realm = cx.getRealm();
if (Type.isObject(options)) {
ScriptObject opts = Type.objectValue(options);
Object fileName = Get(cx, opts, "fileName");
if (!Type.isUndefined(fileName)) {
name = ToFlatString(cx, fileName);
}
Object lineNumber = Get(cx, opts, "lineNumber");
if (!Type.isUndefined(lineNumber)) {
line = ToInt32(cx, lineNumber);
}
Object g = Get(cx, opts, "global");
if (!Type.isUndefined(g)) {
if (!(g instanceof GlobalObject)) {
throw Errors.newError(cx, "invalid global argument");
}
realm = ((GlobalObject) g).getRealm();
}
Object r = Get(cx, opts, "realm");
if (!Type.isUndefined(r)) {
if (!(r instanceof RealmObject)) {
throw Errors.newError(cx, "invalid realm argument");
}
realm = ((RealmObject) r).getRealm();
}
}
Source source = new Source(name, line);
Script script = realm.getScriptLoader().script(source, sourceString);
return script.evaluate(realm);
}
use of com.github.anba.es6draft.runtime.types.ScriptObject 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);
}
Aggregations