/** * Returns a {@code CompilerEnvirons} suitable for using Rhino * in an IDE environment. Most features are enabled by default. * The {@link ErrorReporter} is set to an {@link ErrorCollector}. */ public static CompilerEnvirons ideEnvirons() { CompilerEnvirons env = new CompilerEnvirons(); env.setRecoverFromErrors(true); env.setRecordingComments(true); env.setStrictMode(true); env.setWarnTrailingComma(true); env.setLanguageVersion(170); env.setReservedKeywordAsIdentifier(true); env.setIdeMode(true); env.setErrorReporter(new ErrorCollector()); return env; }
protected void checkActivationName(String name, int token) { if (!insideFunction()) { return; } boolean activation = false; if ("arguments".equals(name) || (compilerEnv.getActivationNames() != null && compilerEnv.getActivationNames().contains(name))) { activation = true; } else if ("length".equals(name)) { if (token == Token.GETPROP && compilerEnv.getLanguageVersion() == Context.VERSION_1_2) { // Use of "length" in 1.2 requires an activation object. activation = true; } } if (activation) { setRequiresActivation(); } }
public IRFactory(CompilerEnvirons env) { this(env, env.getErrorReporter()); }
CompilerEnvirons compilerEnv = new CompilerEnvirons(); compilerEnv.initFromContext(this); compilerEnv.setGeneratingSource(false); Parser p = new Parser(compilerEnv, DefaultErrorReporter.instance); try {
CompilerEnvirons compilerEnv = new CompilerEnvirons(); compilerEnv.initFromContext(this); if (compilationErrorReporter == null) { compilationErrorReporter = compilerEnv.getErrorReporter();
name = createNameNode(true, Token.NAME); if (!matchToken(Token.LP)) { if (compilerEnv.isAllowMemberExprAsFunctionName()) { AstNode memberExprHead = name; name = null; if (compilerEnv.isAllowMemberExprAsFunctionName()) { fnNode.setLength(ts.tokenEnd - functionSourceStart); if (compilerEnv.isStrictMode() && !fnNode.getBody().hasConsistentReturnUsage()) { String msg = (name != null && name.length() > 0) if (compilerEnv.isIdeMode()) { fnNode.setParentScope(currentScope);
&& (!compilerEnv.isUseDynamicScope() || fnCurrent.fnode.getIgnoreDynamicScope())) if (compilerEnv.isGenerateObserverCount()) saveCurrentCodeOffset(); if (compilerEnv.isGenerateDebugInfo()) { String name = fnCurrent.fnode.getParamOrVarName(i); String type = fnCurrent.isNumberVar(i) if (compilerEnv.isGenerateDebugInfo()) { cfw.addVariableDescriptor(debugVariableName, "Lnet/sourceforge/htmlunit/corejs/javascript/Scriptable;",
private AstNode eqExpr() throws IOException { AstNode pn = relExpr(); for (;;) { int tt = peekToken(), opPos = ts.tokenBeg; switch (tt) { case Token.EQ: case Token.NE: case Token.SHEQ: case Token.SHNE: consumeToken(); int parseToken = tt; if (compilerEnv.getLanguageVersion() == Context.VERSION_1_2) { // JavaScript 1.2 uses shallow equality for == and != . if (tt == Token.EQ) parseToken = Token.SHEQ; else if (tt == Token.NE) parseToken = Token.SHNE; } pn = new InfixExpression(parseToken, pn, relExpr(), opPos); continue; } break; } return pn; }
if (result != Token.EOF) { if ((result == Token.LET || result == Token.YIELD) && parser.compilerEnv.getLanguageVersion() < Context.VERSION_1_7) return result; } else if (!parser.compilerEnv. isReservedKeywordAsIdentifier())
private void warnTrailingComma(String messageId, int pos, List<?> elems, int commaPos) { if (compilerEnv.getWarnTrailingComma()) { // back up from comma to beginning of line or array/objlit if (!elems.isEmpty()) { pos = ((AstNode)elems.get(0)).getPosition(); } pos = Math.max(pos, lineBeginningFor(commaPos)); addWarning("msg.extra.trailing.comma", pos, commaPos - pos); } }
if (compilerEnv.isGenerateDebugInfo()) { sourceFile = scriptOrFnNodes[0].getSourceName();
private void generateEpilogue() if (compilerEnv.isGenerateObserverCount()) addInstructionCount(); if (isGenerator) {
public Parser() { this(new CompilerEnvirons()); }
int optLevel = compilerEnv.getOptimizationLevel();
scriptOrFn = tree; itsData = new InterpreterData(compilerEnv.getLanguageVersion(), scriptOrFn.getSourceName(), encodedSource);
if (afterComma != -1 && compilerEnv.getWarnTrailingComma()) warnTrailingComma("msg.extra.trailing.comma", pos, elems, afterComma);
!compilerEnv.isGenerateDebugInfo() && !itsInTryFlag)
if (compilerEnv.isGenerateObserverCount()) { if (compilerEnv.isGenerateObserverCount()) addInstructionCount(); generateThrowJavaScriptException(); if (compilerEnv.isGenerateObserverCount()) addInstructionCount(); cfw.addALoad(getLocalBlockRegister(node)); if (compilerEnv.isGenerateObserverCount()) addInstructionCount(); if (epilogueLabel == -1) { if (compilerEnv.isGenerateObserverCount()) addInstructionCount(); visitSwitch((Jump)node, child); if (compilerEnv.isGenerateObserverCount()) addInstructionCount(); int label = getTargetLabel(node); cfw.markLabel(label); if (compilerEnv.isGenerateObserverCount()) saveCurrentCodeOffset(); case Token.IFEQ: case Token.IFNE: if (compilerEnv.isGenerateObserverCount()) addInstructionCount();
private ObjectProperty plainProperty(AstNode property, int ptt) throws IOException { // Support, e.g., |var {x, y} = o| as destructuring shorthand // for |var {x: x, y: y} = o|, as implemented in spidermonkey JS 1.8. int tt = peekToken(); if ((tt == Token.COMMA || tt == Token.RC) && ptt == Token.NAME && compilerEnv.getLanguageVersion() >= Context.VERSION_1_8) { if (!inDestructuringAssignment) { reportError("msg.bad.object.init"); } AstNode nn = new Name(property.getPosition(), property.getString()); ObjectProperty pn = new ObjectProperty(); pn.putProp(Node.DESTRUCTURING_SHORTHAND, Boolean.TRUE); pn.setLeftAndRight(property, nn); return pn; } mustMatchToken(Token.COLON, "msg.no.colon.prop"); ObjectProperty pn = new ObjectProperty(); pn.setOperatorPosition(ts.tokenBeg); pn.setLeftAndRight(property, assignExpr()); return pn; }
public Parser(CompilerEnvirons compilerEnv) { this(compilerEnv, compilerEnv.getErrorReporter()); }