Search in sources :

Example 16 with ParserException

use of com.github.anba.es6draft.parser.ParserException in project es6draft by anba.

the class RegExpConstructor method RegExpInitialize.

private static RegExpObject RegExpInitialize(ExecutionContext cx, RegExpObject obj, String p, String f) {
    /* steps 7-10 */
    RegExpMatcher matcher;
    try {
        matcher = RegExpParser.parse(p, f, "<regexp>", 1, 1, cx.getRealm().isEnabled(CompatibilityOption.WebRegularExpressions));
    } catch (ParserException e) {
        throw e.toScriptException(cx);
    }
    /* steps 11-13 */
    obj.initialize(p, f, matcher);
    /* steps 14-15 */
    Set(cx, obj, "lastIndex", 0, true);
    /* step 16 */
    return obj;
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) RegExpMatcher(com.github.anba.es6draft.regexp.RegExpMatcher)

Example 17 with ParserException

use of com.github.anba.es6draft.parser.ParserException in project es6draft by anba.

the class ReflectParser method parse.

/**
     * Parses the given script code and returns the matching Reflect AST nodes.
     * 
     * @param cx
     *            the execution context
     * @param sourceCode
     *            the source string
     * @param location
     *            if set to {@code true} node locations will be recorded
     * @param sourceInfo
     *            the source info string
     * @param line
     *            the start line offset
     * @param builder
     *            map to customize AST node processing
     * @return the parsed node
     */
public static Object parse(ExecutionContext cx, String sourceCode, boolean location, String sourceInfo, int line, EnumMap<Type, Callable> builder) {
    Realm realm = cx.getRealm();
    ReflectParser reflect = new ReflectParser(cx, location, sourceInfo, builder);
    Source source = new Source("<parse>", line);
    TopLevelNode<?> parsedNode = null;
    try {
        parsedNode = realm.getScriptLoader().parseScript(source, sourceCode);
    } catch (ParserException ignore) {
        // TODO: Reflect.parse() currently accepts scripts and modules...
        try {
            parsedNode = realm.getScriptLoader().parseModule(source, sourceCode);
        } catch (ParserException e) {
            throw e.toScriptException(cx);
        }
    }
    return parsedNode.accept(reflect, null);
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) Realm(com.github.anba.es6draft.runtime.Realm) Source(com.github.anba.es6draft.runtime.internal.Source)

Example 18 with ParserException

use of com.github.anba.es6draft.parser.ParserException 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);
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) CompilationException(com.github.anba.es6draft.compiler.CompilationException) HashMap(java.util.HashMap) MalformedNameException(com.github.anba.es6draft.runtime.modules.MalformedNameException) ToString(com.github.anba.es6draft.runtime.AbstractOperations.ToString) IOException(java.io.IOException) ResolutionException(com.github.anba.es6draft.runtime.modules.ResolutionException) ModuleExport(com.github.anba.es6draft.runtime.modules.ModuleExport) ModuleRecord(com.github.anba.es6draft.runtime.modules.ModuleRecord) EnvironmentRecord(com.github.anba.es6draft.runtime.EnvironmentRecord) HashSet(java.util.HashSet)

Example 19 with ParserException

use of com.github.anba.es6draft.parser.ParserException in project es6draft by anba.

the class TestAssertions method toAssertionError.

/**
     * Creates a new {@link AssertionError} for the parser exception.
     * 
     * @param e
     *            the script exception
     * @return a new assertion error
     */
public static AssertionError toAssertionError(ParserException e) {
    ParserException exception = withFilteredStackTrace(e);
    AssertionError error = new AssertionError(exception.getMessage(), exception);
    error.setStackTrace(StackTraces.scriptStackTrace(exception));
    return error;
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException)

Example 20 with ParserException

use of com.github.anba.es6draft.parser.ParserException in project es6draft by anba.

the class TestAssertions method withFilteredStackTrace.

private static ParserException withFilteredStackTrace(ParserException e) {
    if (!FILTER_STACK_TRACE) {
        return e;
    }
    ParserException exception = new ParserException(e.getType(), e.getFile(), e.getLine(), e.getColumn(), e.getMessageKey(), e.getMessageArguments());
    exception.setStackTrace(filterStackTrace(e));
    return exception;
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException)

Aggregations

ParserException (com.github.anba.es6draft.parser.ParserException)20 CompilationException (com.github.anba.es6draft.compiler.CompilationException)12 Source (com.github.anba.es6draft.runtime.internal.Source)10 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)8 Realm (com.github.anba.es6draft.runtime.Realm)7 IOException (java.io.IOException)6 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)5 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)5 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)5 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)4 FunctionConstructor.functionSource (com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource)4 Script (com.github.anba.es6draft.Script)3 Function (com.github.anba.es6draft.runtime.internal.Properties.Function)3 ModuleSource (com.github.anba.es6draft.runtime.modules.ModuleSource)3 GlobalObject (com.github.anba.es6draft.runtime.objects.GlobalObject)3 Path (java.nio.file.Path)3 ToSource (com.github.anba.es6draft.repl.SourceBuilder.ToSource)2 SharedFunctions.loadScript (com.github.anba.es6draft.repl.global.SharedFunctions.loadScript)2 SharedFunctions.relativePathToScript (com.github.anba.es6draft.repl.global.SharedFunctions.relativePathToScript)2 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)2