use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class ProxyObject method enumerate.
/**
* 9.5.11 [[Enumerate]] ()
*/
@Override
public ScriptObject enumerate(ExecutionContext cx) {
/* steps 1-3 */
ScriptObject handler = getProxyHandler(cx);
/* step 4 */
ScriptObject target = getProxyTarget();
/* steps 5-6 */
Callable trap = GetMethod(cx, handler, "enumerate");
/* step 7 */
if (trap == null) {
return target.enumerate(cx);
}
/* steps 8-9 */
Object trapResult = trap.call(cx, handler, target);
/* step 10 */
if (!Type.isObject(trapResult)) {
throw newTypeError(cx, Messages.Key.ProxyNotObject);
}
/* step 11 */
return Type.objectValue(trapResult);
}
use of com.github.anba.es6draft.runtime.types.Callable in project es6draft by anba.
the class WrapperProxy method get.
@Override
public Object get(ExecutionContext cx, Symbol 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.Callable in project es6draft by anba.
the class WrapperProxy method set.
@Override
public boolean set(ExecutionContext cx, String 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.Callable in project es6draft by anba.
the class WrapperProxy method get.
@Override
public Object get(ExecutionContext cx, String 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.Callable in project es6draft by anba.
the class ConsoleObject method createConsole.
/**
* Creates a new {@code console} object.
*
* @param realm
* the realm instance
* @return the console object
* @throws IOException
* if there was any I/O error
* @throws URISyntaxException
* the URL is not a valid URI
* @throws MalformedNameException
* if any imported module request cannot be normalized
* @throws ResolutionException
* if any export binding cannot be resolved
*/
public static ScriptObject createConsole(Realm realm) throws IOException, URISyntaxException, MalformedNameException, ResolutionException {
ExecutionContext cx = realm.defaultContext();
ModuleRecord module = NativeCode.loadModule(realm, "console.jsm");
ScriptObject console = NativeCode.getModuleExport(module, "default", ScriptObject.class);
Callable inspectFn = Properties.createFunction(cx, new InspectFunction(), InspectFunction.class);
CreateMethodProperty(cx, console, "_inspect", inspectFn);
return console;
}
Aggregations