use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class ModuleOperations method importMeta.
public static ScriptObject importMeta(ExecutionContext cx) {
/* steps 1-2 */
Executable executable = cx.getActiveScriptOrModule();
assert executable instanceof Module;
SourceIdentifier moduleId = executable.getSource().getSourceId();
Realm realm = cx.getRealm();
ModuleRecord moduleRecord = realm.getModuleLoader().get(moduleId, realm);
/* step 3 */
ScriptObject importMeta = moduleRecord.getMeta();
/* step 4 */
if (importMeta == null) {
/* step 4.a */
importMeta = ObjectCreate(cx, (ScriptObject) null);
/* steps 4.b-e */
cx.getRuntimeContext().getImportMeta().accept(importMeta, moduleRecord);
/* step 4.f */
moduleRecord.setMeta(importMeta);
/* step 4.g */
return importMeta;
}
/* step 5 */
return importMeta;
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class ModuleSemantics method HostResolveImportedModule.
/**
* 15.2.1.17 Runtime Semantics: HostResolveImportedModule (referencingModule, specifier )
*
* @param referencingModule
* the referencing module
* @param specifier
* the module specifier string
* @return the resolved module record
* @throws IOException
* if there was any I/O error
* @throws MalformedNameException
* if the module specifier cannot be normalized
* @throws ResolutionException
* if the module cannot be resolved
* @throws ParserException
* if the module source contains any syntax errors
* @throws CompilationException
* if the parsed module source cannot be compiled
*/
public static ModuleRecord HostResolveImportedModule(ModuleRecord referencingModule, String specifier) throws IOException, MalformedNameException, ResolutionException, ParserException, CompilationException {
Realm realm = referencingModule.getRealm();
assert realm != null : "module is not linked";
ModuleLoader moduleLoader = realm.getModuleLoader();
SourceIdentifier moduleId = moduleLoader.normalizeName(specifier, referencingModule.getSourceCodeId());
try {
return moduleLoader.resolve(moduleId, realm);
} catch (NoSuchFileException e) {
throw new ResolutionException(Messages.Key.ModulesUnresolvedModule, moduleId.toString(), referencingModule.getSourceCodeId().toString());
}
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class FunctionObject method FunctionAllocate.
/**
* 9.2.3 FunctionAllocate (functionPrototype, strict, functionKind)
*
* @param <FUNCTION>
* the function type
* @param cx
* the execution context
* @param allocator
* the function allocator
* @param functionPrototype
* the function prototype
* @param strict
* the strict mode flag
* @param functionKind
* the function kind
* @param constructorKind
* the constructor kind
* @return the new function object
*/
public static <FUNCTION extends FunctionObject> FUNCTION FunctionAllocate(ExecutionContext cx, ObjectAllocator<FUNCTION> allocator, ScriptObject functionPrototype, boolean strict, FunctionKind functionKind, ConstructorKind constructorKind) {
assert constructorKind != ConstructorKind.Derived || functionKind == FunctionKind.ClassConstructor;
Realm realm = cx.getRealm();
/* steps 1-5 (implicit) */
/* steps 6-9 */
FUNCTION f = allocator.newInstance(realm);
FunctionObject fo = (FunctionObject) f;
fo.constructorKind = constructorKind;
/* step 10 */
fo.strict = strict;
/* step 11 */
fo.functionKind = functionKind;
/* step 12 */
fo.setPrototype(functionPrototype);
/* step 13 */
// f.[[Extensible]] = true (implicit)
/* step 14 */
fo.realm = realm;
/* step 15 */
return f;
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class OrdinaryObject method GetPrototypeFromConstructor.
/**
* 9.1.14 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
*
* @param cx
* the execution context
* @param constructor
* the constructor object
* @param intrinsicDefaultProto
* the default prototype
* @return the prototype object
*/
public static final ScriptObject GetPrototypeFromConstructor(ExecutionContext cx, Callable constructor, Intrinsics intrinsicDefaultProto) {
/* steps 1-2 (not applicable) */
/* step 3 */
Object proto = Get(cx, constructor, "prototype");
/* step 4 */
if (!Type.isObject(proto)) {
/* step 4.a */
Realm realm = GetFunctionRealm(cx, constructor);
/* step 4.b */
proto = realm.getIntrinsic(intrinsicDefaultProto);
}
/* step 5 */
return Type.objectValue(proto);
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class ArrayObject method ArraySpeciesCreate.
/**
* 9.4.2.3 ArraySpeciesCreate(originalArray, length)
*
* @param cx
* the execution context
* @param orginalArray
* the source array
* @param length
* the array length
* @return the new array object
*/
public static ScriptObject ArraySpeciesCreate(ExecutionContext cx, ScriptObject orginalArray, long length) {
/* step 1 */
assert length >= 0;
/* steps 3-4 */
if (!IsArray(cx, orginalArray)) {
return ArrayCreate(cx, length);
}
/* step 5 */
Object c = Get(cx, orginalArray, "constructor");
/* step 6 */
if (IsConstructor(c)) {
Constructor constructor = (Constructor) c;
/* step 6.a */
Realm thisRealm = cx.getRealm();
/* step 6.b */
Realm realmC = GetFunctionRealm(cx, constructor);
/* step 6.c */
if (thisRealm != realmC && constructor == realmC.getIntrinsic(Intrinsics.Array)) {
c = UNDEFINED;
}
}
/* step 7 */
if (Type.isObject(c)) {
/* step 7.a.*/
c = Get(cx, Type.objectValue(c), BuiltinSymbol.species.get());
/* step 7.b */
if (Type.isNull(c)) {
c = UNDEFINED;
}
}
/* step 8 */
if (Type.isUndefined(c)) {
return ArrayCreate(cx, length);
}
/* step 9 */
if (!IsConstructor(c)) {
throw newTypeError(cx, Messages.Key.NotConstructor);
}
/* step 10 */
return ((Constructor) c).construct(cx, length);
}
Aggregations