use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class ArrayBufferConstructor method AllocateArrayBuffer.
/**
* 24.1.1.1 AllocateArrayBuffer( constructor, byteLength )
*
* @param cx
* the execution context
* @param constructor
* the constructor function
* @param byteLength
* the buffer byte length
* @return the new array buffer object
*/
public static ArrayBufferObject AllocateArrayBuffer(ExecutionContext cx, Constructor constructor, long byteLength) {
/* steps 1-2 */
ScriptObject proto = GetPrototypeFromConstructor(cx, constructor, Intrinsics.ArrayBufferPrototype);
/* step 3 */
assert byteLength >= 0;
/* steps 4-5 */
ByteBuffer block = CreateByteDataBlock(cx, byteLength);
/* steps 1-2, 6-8 */
return new ArrayBufferObject(cx.getRealm(), block, byteLength, proto);
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class ModuleSemantics method GetModuleNamespace.
/**
* 15.2.1.18 Runtime Semantics: GetModuleNamespace( module )
*
* @param cx
* the execution context
* @param module
* the module record
* @return the module namespace object
* @throws IOException
* if there was any I/O error
* @throws MalformedNameException
* if any imported module request cannot be normalized
* @throws ResolutionException
* if any export binding cannot be resolved
*/
public static ScriptObject GetModuleNamespace(ExecutionContext cx, ModuleRecord module) throws IOException, MalformedNameException, ResolutionException {
/* step 1 (not applicable) */
/* step 2 */
ScriptObject namespace = module.getNamespace();
/* step 3 */
if (namespace == null) {
/* steps 3.a-b */
Set<String> exportedNames = module.getExportedNames(new HashSet<>());
/* step 3.c */
Set<String> unambiguousNames = new HashSet<>();
/* step 3.d */
for (String name : exportedNames) {
ModuleExport resolution = module.resolveExport(name, new HashMap<>(), new HashSet<>());
if (resolution == null) {
throw new ResolutionException(Messages.Key.ModulesUnresolvedExport, name);
}
if (!resolution.isAmbiguous()) {
unambiguousNames.add(name);
}
}
/* step 3.e */
namespace = ModuleNamespaceCreate(cx, module, unambiguousNames);
}
/* step 4 */
return namespace;
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class PropertiesTest method createCustomClassNoArgs.
@Test
public void createCustomClassNoArgs() {
Constructor customClass = Properties.createClass(cx, "CustomClassNoArgs", CustomClassNoArgs.ConstructorProperties.class, CustomClassNoArgs.PrototypeProperties.class);
ScriptObject object = customClass.construct(cx, customClass);
assertNotNull(object);
}
use of com.github.anba.es6draft.runtime.types.ScriptObject in project es6draft by anba.
the class PropertiesTest method createCustomClassWithSubclass.
@Test
public void createCustomClassWithSubclass() {
Constructor customClass = Properties.createClass(cx, "CustomClassWithSubclass", CustomClassWithSubclass.ConstructorProperties.class, CustomClassWithSubclass.PrototypeProperties.class);
ScriptObject object = customClass.construct(cx, customClass);
assertNotNull(object);
}
use of com.github.anba.es6draft.runtime.types.ScriptObject 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);
}
}
Aggregations