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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations