use of com.github.anba.es6draft.compiler.CompilationException in project es6draft by anba.
the class FunctionConstructor method CreateDynamicFunction.
/**
* 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)
*
* @param callerContext
* the caller execution context
* @param cx
* the execution context
* @param newTarget
* the newTarget constructor function
* @param args
* the function arguments
* @return the new function object
*/
private static FunctionObject CreateDynamicFunction(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
/* step 1 (not applicable) */
/* step 2 */
Intrinsics fallbackProto = Intrinsics.FunctionPrototype;
/* step 3 (not applicable) */
/* steps 4-10 */
String[] sourceText = functionSourceText(cx, args);
String parameters = sourceText[0], bodyText = sourceText[1];
/* steps 11, 13-20 */
Source source = functionSource(SourceKind.Function, cx.getRealm(), callerContext);
RuntimeInfo.Function function;
try {
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
function = scriptLoader.function(source, parameters, bodyText).getFunction();
} catch (ParserException | CompilationException e) {
throw e.toScriptException(cx);
}
/* steps 12, 21-30 */
return CreateDynamicFunction(cx, source, function, newTarget, fallbackProto);
}
use of com.github.anba.es6draft.compiler.CompilationException 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);
}
Aggregations