use of com.github.anba.es6draft.runtime.modules.ResolutionException in project es6draft by anba.
the class NodeModuleLoader method createModuleObject.
private ScriptObject createModuleObject(NodeModuleRecord module, Realm realm) {
Constructor moduleConstructor = moduleConstructors.computeIfAbsent(realm, r -> {
try {
ModuleRecord mod = ScriptLoading.evalNativeModule(r, "module.jsm");
return (Constructor) ScriptLoading.getModuleExport(mod, "default");
} catch (MalformedNameException | ResolutionException e) {
throw e.toScriptException(r.defaultContext());
} catch (IOException e) {
throw Errors.newError(r.defaultContext(), e.getMessage());
}
});
Path file = module.getSource().getFile();
String fileName = Objects.toString(file, "");
String dirName = file != null ? Objects.toString(file.getParent(), "") : "";
return Construct(realm.defaultContext(), moduleConstructor, fileName, dirName);
}
use of com.github.anba.es6draft.runtime.modules.ResolutionException in project es6draft by anba.
the class ModuleNamespaceObject method get.
/**
* 9.4.6.7 [[Get]] (P, Receiver)
*/
@Override
public Object get(ExecutionContext cx, String propertyKey, Object receiver) {
/* steps 1-2 (not applicable) */
/* step 3 */
Set<String> exports = this.exports;
/* step 4 */
if (!exports.contains(propertyKey)) {
return UNDEFINED;
}
/* step 5 */
ModuleRecord m = this.module;
/* step 6 */
ResolvedBinding binding;
try {
binding = m.resolveExport(propertyKey, new HashMap<>());
} catch (IOException e) {
throw Errors.newInternalError(cx, e, Messages.Key.ModulesIOException, e.getMessage());
} catch (ResolutionException | MalformedNameException | ParserException | CompilationException e) {
throw e.toScriptException(cx);
}
/* step 7 */
assert binding != null && !binding.isAmbiguous();
/* step 8 */
ModuleRecord targetModule = binding.getModule();
/* step 9 */
assert targetModule != null;
/* step 10 */
LexicalEnvironment<?> targetEnv = targetModule.getEnvironment();
/* step 11 */
if (targetEnv == null) {
throw newReferenceError(cx, Messages.Key.UninitializedBinding, binding.getBindingName());
}
/* step ? (Extension: Export From) */
if (binding.isNameSpaceExport()) {
try {
return GetModuleNamespace(cx, targetModule);
} catch (IOException e) {
throw Errors.newInternalError(cx, Messages.Key.ModulesIOException, e.getMessage());
} catch (MalformedNameException | ResolutionException e) {
throw e.toScriptException(cx);
}
}
/* step 12 */
EnvironmentRecord targetEnvRec = targetEnv.getEnvRec();
/* step 13 */
return targetEnvRec.getBindingValue(binding.getBindingName(), true);
}
use of com.github.anba.es6draft.runtime.modules.ResolutionException in project es6draft by anba.
the class ModuleNamespaceObject method getValue.
/** 9.4.6.8 [[Get]] (P, Receiver) */
@Override
protected Object getValue(ExecutionContext cx, String propertyKey, Object receiver) {
/* step 1 (not applicable) */
/* step 2 (not applicable) */
/* step 3 */
Set<String> exports = this.exports;
/* step 4 */
if (!exports.contains(propertyKey)) {
return UNDEFINED;
}
/* step 5 */
ModuleRecord m = this.module;
/* steps 6-8 */
ModuleExport binding;
try {
/* steps 6, 8 */
binding = m.resolveExport(propertyKey, new HashMap<>(), new HashSet<>());
} catch (IOException e) {
/* step 7 */
throw Errors.newInternalError(cx, e, Messages.Key.ModulesIOException, e.getMessage());
} catch (ResolutionException | MalformedNameException e) {
/* step 7 */
throw e.toScriptException(cx);
} catch (ParserException | CompilationException e) {
/* step 7 */
throw e.toScriptException(cx);
}
/* step 8 */
assert binding != null && !binding.isAmbiguous();
/* step 9 */
ModuleRecord targetModule = binding.getModule();
/* step 10 */
assert targetModule != null;
/* step 11 */
LexicalEnvironment<?> targetEnv = targetModule.getEnvironment();
/* step 12 */
if (targetEnv == null) {
throw newReferenceError(cx, Messages.Key.UninitializedBinding, binding.getBindingName());
}
/* step ? (Extension: Export From) */
if (binding.isNameSpaceExport()) {
try {
return GetModuleNamespace(cx, targetModule);
} catch (IOException e) {
throw Errors.newInternalError(cx, Messages.Key.ModulesIOException, e.getMessage());
} catch (MalformedNameException | ResolutionException e) {
throw e.toScriptException(cx);
}
}
/* step 13 */
EnvironmentRecord targetEnvRec = targetEnv.getEnvRec();
/* step 14 */
return targetEnvRec.getBindingValue(binding.getBindingName(), true);
}
use of com.github.anba.es6draft.runtime.modules.ResolutionException in project es6draft by anba.
the class Test262TestRealm method execute.
/**
* Executes the supplied test object.
*
* @param test
* the test-info object
* @throws IOException
* if there was any I/O error
* @throws MalformedNameException
* if any imported module request cannot be normalized
* @throws ParserException
* if the module source contains any syntax errors
* @throws CompilationException
* if the parsed module source cannot be compiled
*/
void execute(Test262Info test) throws ParserException, CompilationException, IOException, MalformedNameException {
// Return early if no source code is available.
if (sourceCode == null) {
return;
}
assert !test.isAsync() || async != null;
Realm realm = get();
// Parse and evaluate the test-script
if (test.isModule()) {
ModuleLoader moduleLoader = realm.getModuleLoader();
String moduleName = test.toModuleName();
SourceIdentifier moduleId = moduleLoader.normalizeName(moduleName, null);
ModuleSource source = new StringModuleSource(moduleId, moduleName, sourceCode);
ModuleRecord module = moduleLoader.define(moduleId, source, realm);
try {
module.instantiate();
} catch (ResolutionException e) {
throw e.toScriptException(realm.defaultContext());
}
// Return after module instantiation if we test for module resolution errors.
if (test.getErrorPhase() == ErrorPhase.Resolution) {
return;
}
try {
module.evaluate();
} catch (ResolutionException e) {
throw e.toScriptException(realm.defaultContext());
}
} else {
Source source = new Source(test.toFile(), test.getScript().toString(), 1);
Script script = realm.getScriptLoader().script(source, sourceCode);
script.evaluate(realm);
}
// Wait for pending jobs to finish
waitForPendingJobs(realm, test);
}
use of com.github.anba.es6draft.runtime.modules.ResolutionException in project es6draft by anba.
the class ModuleOperations method FinishDynamicImport.
/**
* Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion )
*/
private static void FinishDynamicImport(ExecutionContext cx, String specifier, PromiseCapability<PromiseObject> promiseCapability, ModuleRecord module, SourceIdentifier referredId) {
ScriptObject namespace;
try {
// FIXME: spec issue - module namespace with "then" property vs. promise thenables
namespace = GetModuleNamespace(cx, module);
} catch (ScriptException | IOException | MalformedNameException | ResolutionException e) {
ScriptException exception = toScriptException(cx, e, module.getSourceCodeId(), referredId);
promiseCapability.getReject().call(cx, UNDEFINED, exception.getValue());
return;
}
promiseCapability.getResolve().call(cx, UNDEFINED, namespace);
}
Aggregations