Changeset 198980 in webkit
- Timestamp:
- Apr 3, 2016 12:59:19 AM (8 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r198979 r198980 1 2016-04-03 Skachkov Oleksandr <gskachkov@gmail.com> 2 3 [ES6] Class syntax. Access to new.target inside of the eval should not lead to SyntaxError 4 https://bugs.webkit.org/show_bug.cgi?id=155545 5 6 Reviewed by Saam Barati. 7 8 Current patch allow to invoke new.target in eval if this eval is executed within function, 9 otherwise this will lead to Syntax error 10 11 * bytecode/EvalCodeCache.h: 12 (JSC::EvalCodeCache::getSlow): 13 * bytecode/ExecutableInfo.h: 14 (JSC::ExecutableInfo::ExecutableInfo): 15 (JSC::ExecutableInfo::evalContextType): 16 * bytecode/UnlinkedCodeBlock.cpp: 17 (JSC::UnlinkedCodeBlock::UnlinkedCodeBlock): 18 * bytecode/UnlinkedCodeBlock.h: 19 (JSC::UnlinkedCodeBlock::evalContextType): 20 * bytecode/UnlinkedFunctionExecutable.cpp: 21 (JSC::generateUnlinkedFunctionCodeBlock): 22 * debugger/DebuggerCallFrame.cpp: 23 (JSC::DebuggerCallFrame::evaluate): 24 * interpreter/Interpreter.cpp: 25 (JSC::eval): 26 * parser/Parser.cpp: 27 (JSC::Parser<LexerType>::Parser): 28 (JSC::Parser<LexerType>::parseMemberExpression): 29 * parser/Parser.h: 30 (JSC::Scope::Scope): 31 (JSC::Scope::setEvalContextType): 32 (JSC::Scope::evalContextType): 33 (JSC::parse): 34 * runtime/CodeCache.cpp: 35 (JSC::CodeCache::getGlobalCodeBlock): 36 (JSC::CodeCache::getProgramCodeBlock): 37 (JSC::CodeCache::getEvalCodeBlock): 38 (JSC::CodeCache::getModuleProgramCodeBlock): 39 * runtime/CodeCache.h: 40 * runtime/Executable.cpp: 41 (JSC::ScriptExecutable::ScriptExecutable): 42 (JSC::EvalExecutable::create): 43 (JSC::EvalExecutable::EvalExecutable): 44 (JSC::ProgramExecutable::ProgramExecutable): 45 (JSC::ModuleProgramExecutable::ModuleProgramExecutable): 46 (JSC::FunctionExecutable::FunctionExecutable): 47 * runtime/Executable.h: 48 (JSC::ScriptExecutable::evalContextType): 49 * runtime/JSGlobalObject.cpp: 50 (JSC::JSGlobalObject::createEvalCodeBlock): 51 * runtime/JSGlobalObjectFunctions.cpp: 52 (JSC::globalFuncEval): 53 * tests/stress/arrowfunction-lexical-bind-newtarget.js: 54 * tests/stress/new-target.js: 55 1 56 2016-04-02 Commit Queue <commit-queue@webkit.org> 2 57 -
trunk/Source/JavaScriptCore/bytecode/EvalCodeCache.h
r198778 r198980 99 99 } 100 100 101 EvalExecutable* getSlow(ExecState* exec, JSCell* owner, bool inStrictContext, ThisTDZMode thisTDZMode, DerivedContextType derivedContextType, bool isArrowFunctionContext, const String& evalSource, JSScope* scope)101 EvalExecutable* getSlow(ExecState* exec, JSCell* owner, bool inStrictContext, ThisTDZMode thisTDZMode, DerivedContextType derivedContextType, bool isArrowFunctionContext, EvalContextType evalContextType, const String& evalSource, JSScope* scope) 102 102 { 103 103 VariableEnvironment variablesUnderTDZ; 104 104 JSScope::collectVariablesUnderTDZ(scope, variablesUnderTDZ); 105 EvalExecutable* evalExecutable = EvalExecutable::create(exec, makeSource(evalSource), inStrictContext, thisTDZMode, derivedContextType, isArrowFunctionContext, &variablesUnderTDZ);105 EvalExecutable* evalExecutable = EvalExecutable::create(exec, makeSource(evalSource), inStrictContext, thisTDZMode, derivedContextType, isArrowFunctionContext, evalContextType, &variablesUnderTDZ); 106 106 if (!evalExecutable) 107 107 return nullptr; -
trunk/Source/JavaScriptCore/bytecode/ExecutableInfo.h
r197043 r198980 32 32 33 33 enum class DerivedContextType : uint8_t { None, DerivedConstructorContext, DerivedMethodContext }; 34 enum class EvalContextType : uint8_t { None, FunctionEvalContext }; 34 35 35 36 // FIXME: These flags, ParserModes and propagation to XXXCodeBlocks should be reorganized. 36 37 // https://bugs.webkit.org/show_bug.cgi?id=151547 37 38 struct ExecutableInfo { 38 ExecutableInfo(bool usesEval, bool isStrictMode, bool isConstructor, bool isBuiltinFunction, ConstructorKind constructorKind, SuperBinding superBinding, SourceParseMode parseMode, DerivedContextType derivedContextType, bool isArrowFunctionContext, bool isClassContext )39 ExecutableInfo(bool usesEval, bool isStrictMode, bool isConstructor, bool isBuiltinFunction, ConstructorKind constructorKind, SuperBinding superBinding, SourceParseMode parseMode, DerivedContextType derivedContextType, bool isArrowFunctionContext, bool isClassContext, EvalContextType evalContextType) 39 40 : m_usesEval(usesEval) 40 41 , m_isStrictMode(isStrictMode) … … 47 48 , m_isArrowFunctionContext(isArrowFunctionContext) 48 49 , m_isClassContext(isClassContext) 50 , m_evalContextType(static_cast<unsigned>(evalContextType)) 49 51 { 50 52 ASSERT(m_constructorKind == static_cast<unsigned>(constructorKind)); … … 60 62 SourceParseMode parseMode() const { return m_parseMode; } 61 63 DerivedContextType derivedContextType() const { return static_cast<DerivedContextType>(m_derivedContextType); } 64 EvalContextType evalContextType() const { return static_cast<EvalContextType>(m_evalContextType); } 62 65 bool isArrowFunctionContext() const { return m_isArrowFunctionContext; } 63 66 bool isClassContext() const { return m_isClassContext; } … … 74 77 unsigned m_isArrowFunctionContext : 1; 75 78 unsigned m_isClassContext : 1; 79 unsigned m_evalContextType : 2; 76 80 }; 77 81 -
trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp
r197379 r198980 66 66 , m_superBinding(static_cast<unsigned>(info.superBinding())) 67 67 , m_derivedContextType(static_cast<unsigned>(info.derivedContextType())) 68 , m_evalContextType(static_cast<unsigned>(info.evalContextType())) 68 69 , m_isArrowFunctionContext(info.isArrowFunctionContext()) 69 70 , m_isClassContext(info.isClassContext()) -
trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h
r197686 r198980 121 121 bool isArrowFunction() const { return m_parseMode == SourceParseMode::ArrowFunctionMode; } 122 122 DerivedContextType derivedContextType() const { return static_cast<DerivedContextType>(m_derivedContextType); } 123 EvalContextType evalContextType() const { return static_cast<EvalContextType>(m_evalContextType); } 123 124 bool isArrowFunctionContext() const { return m_isArrowFunctionContext; } 124 125 bool isClassContext() const { return m_isClassContext; } … … 398 399 unsigned m_superBinding : 1; 399 400 unsigned m_derivedContextType : 2; 401 unsigned m_evalContextType : 2; 400 402 unsigned m_isArrowFunctionContext : 1; 401 403 unsigned m_isClassContext : 1; -
trunk/Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.cpp
r198798 r198980 69 69 bool isClassContext = executable->superBinding() == SuperBinding::Needed; 70 70 71 UnlinkedFunctionCodeBlock* result = UnlinkedFunctionCodeBlock::create(&vm, FunctionCode, 72 ExecutableInfo(function->usesEval(), function->isStrictMode(), kind == CodeForConstruct, functionKind == UnlinkedBuiltinFunction, executable->constructorKind(), executable->superBinding(), parseMode, executable->derivedContextType(), false, isClassContext)); 71 UnlinkedFunctionCodeBlock* result = UnlinkedFunctionCodeBlock::create(&vm, FunctionCode, ExecutableInfo(function->usesEval(), function->isStrictMode(), kind == CodeForConstruct, functionKind == UnlinkedBuiltinFunction, executable->constructorKind(), executable->superBinding(), parseMode, executable->derivedContextType(), false, isClassContext, EvalContextType::FunctionEvalContext)); 73 72 74 73 auto generator(std::make_unique<BytecodeGenerator>(vm, function.get(), result, debuggerMode, profilerMode, executable->parentScopeTDZVariables())); -
trunk/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp
r194449 r198980 190 190 ThisTDZMode thisTDZMode = codeBlock.unlinkedCodeBlock()->constructorKind() == ConstructorKind::Derived ? ThisTDZMode::AlwaysCheck : ThisTDZMode::CheckIfNeeded; 191 191 192 EvalContextType evalContextType; 193 194 if (isFunctionParseMode(codeBlock.unlinkedCodeBlock()->parseMode())) 195 evalContextType = EvalContextType::FunctionEvalContext; 196 else if (codeBlock.unlinkedCodeBlock()->codeType() == EvalCode) 197 evalContextType = codeBlock.unlinkedCodeBlock()->evalContextType(); 198 else 199 evalContextType = EvalContextType::None; 200 192 201 VariableEnvironment variablesUnderTDZ; 193 202 JSScope::collectVariablesUnderTDZ(scope()->jsScope(), variablesUnderTDZ); 194 203 195 EvalExecutable* eval = EvalExecutable::create(callFrame, makeSource(script), codeBlock.isStrictMode(), thisTDZMode, codeBlock.unlinkedCodeBlock()->derivedContextType(), codeBlock.unlinkedCodeBlock()->isArrowFunction(), &variablesUnderTDZ);204 EvalExecutable* eval = EvalExecutable::create(callFrame, makeSource(script), codeBlock.isStrictMode(), thisTDZMode, codeBlock.unlinkedCodeBlock()->derivedContextType(), codeBlock.unlinkedCodeBlock()->isArrowFunction(), evalContextType, &variablesUnderTDZ); 196 205 if (vm.exception()) { 197 206 exception = vm.exception(); -
trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp
r198778 r198980 188 188 : DerivedContextType::DerivedMethodContext; 189 189 } 190 191 eval = callerCodeBlock->evalCodeCache().getSlow(callFrame, callerCodeBlock, callerCodeBlock->isStrictMode(), thisTDZMode, derivedContextType, isArrowFunctionContext, programSource, callerScopeChain); 190 191 EvalContextType evalContextType; 192 193 if (isFunctionParseMode(callerUnlinkedCodeBlock->parseMode())) 194 evalContextType = EvalContextType::FunctionEvalContext; 195 else if (callerUnlinkedCodeBlock->codeType() == EvalCode) 196 evalContextType = callerUnlinkedCodeBlock->evalContextType(); 197 else 198 evalContextType = EvalContextType::None; 199 200 eval = callerCodeBlock->evalCodeCache().getSlow(callFrame, callerCodeBlock, callerCodeBlock->isStrictMode(), thisTDZMode, derivedContextType, isArrowFunctionContext, evalContextType, programSource, callerScopeChain); 201 192 202 if (!eval) 193 203 return jsUndefined(); -
trunk/Source/JavaScriptCore/parser/Parser.cpp
r198928 r198980 192 192 193 193 template <typename LexerType> 194 Parser<LexerType>::Parser(VM* vm, const SourceCode& source, JSParserBuiltinMode builtinMode, JSParserStrictMode strictMode, SourceParseMode parseMode, SuperBinding superBinding, ConstructorKind defaultConstructorKind, ThisTDZMode thisTDZMode, DerivedContextType derivedContextType, bool isEvalContext )194 Parser<LexerType>::Parser(VM* vm, const SourceCode& source, JSParserBuiltinMode builtinMode, JSParserStrictMode strictMode, SourceParseMode parseMode, SuperBinding superBinding, ConstructorKind defaultConstructorKind, ThisTDZMode thisTDZMode, DerivedContextType derivedContextType, bool isEvalContext, EvalContextType evalContextType) 195 195 : m_vm(vm) 196 196 , m_source(&source) … … 217 217 scope->setSourceParseMode(parseMode); 218 218 scope->setIsEvalContext(isEvalContext); 219 if (isEvalContext) 220 scope->setEvalContextType(evalContextType); 219 221 220 222 if (derivedContextType == DerivedContextType::DerivedConstructorContext) { … … 3860 3862 const Identifier* ident = m_token.m_data.ident; 3861 3863 if (m_vm->propertyNames->target == *ident) { 3862 semanticFailIfFalse(currentScope()->isFunction() , "new.target is only valid inside functions");3864 semanticFailIfFalse(currentScope()->isFunction() || closestParentOrdinaryFunctionNonLexicalScope()->evalContextType() == EvalContextType::FunctionEvalContext, "new.target is only valid inside functions"); 3863 3865 baseIsNewTarget = true; 3864 3866 if (currentScope()->isArrowFunction()) -
trunk/Source/JavaScriptCore/parser/Parser.h
r198932 r198980 176 176 , m_hasArguments(false) 177 177 , m_isEvalContext(false) 178 , m_evalContextType(EvalContextType::None) 178 179 , m_constructorKind(static_cast<unsigned>(ConstructorKind::None)) 179 180 , m_expectedSuperBinding(static_cast<unsigned>(SuperBinding::NotNeeded)) … … 525 526 void setNeedsSuperBinding() { m_needsSuperBinding = true; } 526 527 528 void setEvalContextType(EvalContextType evalContextType) { m_evalContextType = evalContextType; } 529 EvalContextType evalContextType() { return m_evalContextType; } 530 527 531 InnerArrowFunctionCodeFeatures innerArrowFunctionFeatures() { return m_innerArrowFunctionFeatures; } 528 532 … … 726 730 bool m_hasArguments; 727 731 bool m_isEvalContext; 732 EvalContextType m_evalContextType; 728 733 unsigned m_constructorKind; 729 734 unsigned m_expectedSuperBinding; … … 782 787 783 788 public: 784 Parser(VM*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, SourceParseMode, SuperBinding, ConstructorKind defaultConstructorKind = ConstructorKind::None, ThisTDZMode = ThisTDZMode::CheckIfNeeded, DerivedContextType = DerivedContextType::None, bool isEvalContext = false );789 Parser(VM*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, SourceParseMode, SuperBinding, ConstructorKind defaultConstructorKind = ConstructorKind::None, ThisTDZMode = ThisTDZMode::CheckIfNeeded, DerivedContextType = DerivedContextType::None, bool isEvalContext = false, EvalContextType = EvalContextType::None); 785 790 ~Parser(); 786 791 … … 1662 1667 JSParserStrictMode strictMode, SourceParseMode parseMode, SuperBinding superBinding, 1663 1668 ParserError& error, JSTextPosition* positionBeforeLastNewline = nullptr, 1664 ConstructorKind defaultConstructorKind = ConstructorKind::None, ThisTDZMode thisTDZMode = ThisTDZMode::CheckIfNeeded, 1665 DerivedContextType derivedContextType = DerivedContextType::None )1669 ConstructorKind defaultConstructorKind = ConstructorKind::None, ThisTDZMode thisTDZMode = ThisTDZMode::CheckIfNeeded, 1670 DerivedContextType derivedContextType = DerivedContextType::None, EvalContextType evalContextType = EvalContextType::None) 1666 1671 { 1667 1672 ASSERT(!source.provider()->source().isNull()); 1668 1673 if (source.provider()->source().is8Bit()) { 1669 Parser<Lexer<LChar>> parser(vm, source, builtinMode, strictMode, parseMode, superBinding, defaultConstructorKind, thisTDZMode, derivedContextType, isEvalNode<ParsedNode>() );1674 Parser<Lexer<LChar>> parser(vm, source, builtinMode, strictMode, parseMode, superBinding, defaultConstructorKind, thisTDZMode, derivedContextType, isEvalNode<ParsedNode>(), evalContextType); 1670 1675 std::unique_ptr<ParsedNode> result = parser.parse<ParsedNode>(error, name, parseMode); 1671 1676 if (positionBeforeLastNewline) … … 1678 1683 } 1679 1684 ASSERT_WITH_MESSAGE(defaultConstructorKind == ConstructorKind::None, "BuiltinExecutables::createDefaultConstructor should always use a 8-bit string"); 1680 Parser<Lexer<UChar>> parser(vm, source, builtinMode, strictMode, parseMode, superBinding, defaultConstructorKind, thisTDZMode, derivedContextType, isEvalNode<ParsedNode>() );1685 Parser<Lexer<UChar>> parser(vm, source, builtinMode, strictMode, parseMode, superBinding, defaultConstructorKind, thisTDZMode, derivedContextType, isEvalNode<ParsedNode>(), evalContextType); 1681 1686 std::unique_ptr<ParsedNode> result = parser.parse<ParsedNode>(error, name, parseMode); 1682 1687 if (positionBeforeLastNewline) -
trunk/Source/JavaScriptCore/runtime/CodeCache.cpp
r198324 r198980 30 30 #include "BytecodeGenerator.h" 31 31 #include "CodeSpecializationKind.h" 32 #include "ExecutableInfo.h" 32 33 #include "JSCInlines.h" 33 34 #include "Parser.h" … … 84 85 85 86 template <class UnlinkedCodeBlockType, class ExecutableType> 86 UnlinkedCodeBlockType* CodeCache::getGlobalCodeBlock(VM& vm, ExecutableType* executable, const SourceCode& source, JSParserBuiltinMode builtinMode, JSParserStrictMode strictMode, ThisTDZMode thisTDZMode, bool, DebuggerMode debuggerMode, ProfilerMode profilerMode, ParserError& error, const VariableEnvironment* variablesUnderTDZ)87 UnlinkedCodeBlockType* CodeCache::getGlobalCodeBlock(VM& vm, ExecutableType* executable, const SourceCode& source, JSParserBuiltinMode builtinMode, JSParserStrictMode strictMode, ThisTDZMode thisTDZMode, bool, DebuggerMode debuggerMode, ProfilerMode profilerMode, ParserError& error, EvalContextType evalContextType, const VariableEnvironment* variablesUnderTDZ) 87 88 { 88 89 SourceCodeKey key = SourceCodeKey(source, String(), CacheTypes<UnlinkedCodeBlockType>::codeType, builtinMode, strictMode, thisTDZMode); … … 104 105 DerivedContextType derivedContextType = executable->derivedContextType(); 105 106 std::unique_ptr<RootNode> rootNode = parse<RootNode>( 106 &vm, source, Identifier(), builtinMode, strictMode, CacheTypes<UnlinkedCodeBlockType>::parseMode, SuperBinding::NotNeeded, error, nullptr, ConstructorKind::None, thisTDZMode, derivedContextType );107 &vm, source, Identifier(), builtinMode, strictMode, CacheTypes<UnlinkedCodeBlockType>::parseMode, SuperBinding::NotNeeded, error, nullptr, ConstructorKind::None, thisTDZMode, derivedContextType, evalContextType); 107 108 if (!rootNode) 108 109 return nullptr; … … 134 135 { 135 136 VariableEnvironment emptyParentTDZVariables; 136 return getGlobalCodeBlock<UnlinkedProgramCodeBlock>(vm, executable, source, builtinMode, strictMode, ThisTDZMode::CheckIfNeeded, false, debuggerMode, profilerMode, error, &emptyParentTDZVariables);137 } 138 139 UnlinkedEvalCodeBlock* CodeCache::getEvalCodeBlock(VM& vm, EvalExecutable* executable, const SourceCode& source, JSParserBuiltinMode builtinMode, JSParserStrictMode strictMode, ThisTDZMode thisTDZMode, bool isArrowFunctionContext, DebuggerMode debuggerMode, ProfilerMode profilerMode, ParserError& error, const VariableEnvironment* variablesUnderTDZ)140 { 141 return getGlobalCodeBlock<UnlinkedEvalCodeBlock>(vm, executable, source, builtinMode, strictMode, thisTDZMode, isArrowFunctionContext, debuggerMode, profilerMode, error, variablesUnderTDZ);137 return getGlobalCodeBlock<UnlinkedProgramCodeBlock>(vm, executable, source, builtinMode, strictMode, ThisTDZMode::CheckIfNeeded, false, debuggerMode, profilerMode, error, EvalContextType::None, &emptyParentTDZVariables); 138 } 139 140 UnlinkedEvalCodeBlock* CodeCache::getEvalCodeBlock(VM& vm, EvalExecutable* executable, const SourceCode& source, JSParserBuiltinMode builtinMode, JSParserStrictMode strictMode, ThisTDZMode thisTDZMode, bool isArrowFunctionContext, DebuggerMode debuggerMode, ProfilerMode profilerMode, ParserError& error, EvalContextType evalContextType, const VariableEnvironment* variablesUnderTDZ) 141 { 142 return getGlobalCodeBlock<UnlinkedEvalCodeBlock>(vm, executable, source, builtinMode, strictMode, thisTDZMode, isArrowFunctionContext, debuggerMode, profilerMode, error, evalContextType, variablesUnderTDZ); 142 143 } 143 144 … … 145 146 { 146 147 VariableEnvironment emptyParentTDZVariables; 147 return getGlobalCodeBlock<UnlinkedModuleProgramCodeBlock>(vm, executable, source, builtinMode, JSParserStrictMode::Strict, ThisTDZMode::CheckIfNeeded, false, debuggerMode, profilerMode, error, &emptyParentTDZVariables);148 return getGlobalCodeBlock<UnlinkedModuleProgramCodeBlock>(vm, executable, source, builtinMode, JSParserStrictMode::Strict, ThisTDZMode::CheckIfNeeded, false, debuggerMode, profilerMode, error, EvalContextType::None, &emptyParentTDZVariables); 148 149 } 149 150 -
trunk/Source/JavaScriptCore/runtime/CodeCache.h
r193766 r198980 28 28 29 29 #include "CodeSpecializationKind.h" 30 #include "ExecutableInfo.h" 30 31 #include "ParserModes.h" 31 32 #include "SourceCode.h" … … 195 196 196 197 UnlinkedProgramCodeBlock* getProgramCodeBlock(VM&, ProgramExecutable*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, DebuggerMode, ProfilerMode, ParserError&); 197 UnlinkedEvalCodeBlock* getEvalCodeBlock(VM&, EvalExecutable*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, ThisTDZMode, bool, DebuggerMode, ProfilerMode, ParserError&, const VariableEnvironment*);198 UnlinkedEvalCodeBlock* getEvalCodeBlock(VM&, EvalExecutable*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, ThisTDZMode, bool, DebuggerMode, ProfilerMode, ParserError&, EvalContextType, const VariableEnvironment*); 198 199 UnlinkedModuleProgramCodeBlock* getModuleProgramCodeBlock(VM&, ModuleProgramExecutable*, const SourceCode&, JSParserBuiltinMode, DebuggerMode, ProfilerMode, ParserError&); 199 200 UnlinkedFunctionExecutable* getFunctionExecutableFromGlobalCode(VM&, const Identifier&, const SourceCode&, ParserError&); … … 206 207 private: 207 208 template <class UnlinkedCodeBlockType, class ExecutableType> 208 UnlinkedCodeBlockType* getGlobalCodeBlock(VM&, ExecutableType*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, ThisTDZMode, bool, DebuggerMode, ProfilerMode, ParserError&, const VariableEnvironment*);209 UnlinkedCodeBlockType* getGlobalCodeBlock(VM&, ExecutableType*, const SourceCode&, JSParserBuiltinMode, JSParserStrictMode, ThisTDZMode, bool, DebuggerMode, ProfilerMode, ParserError&, EvalContextType, const VariableEnvironment*); 209 210 210 211 CodeCacheMap m_sourceCode; -
trunk/Source/JavaScriptCore/runtime/Executable.cpp
r198798 r198980 111 111 const ClassInfo ScriptExecutable::s_info = { "ScriptExecutable", &ExecutableBase::s_info, 0, CREATE_METHOD_TABLE(ScriptExecutable) }; 112 112 113 ScriptExecutable::ScriptExecutable(Structure* structure, VM& vm, const SourceCode& source, bool isInStrictContext, DerivedContextType derivedContextType, bool isInArrowFunctionContext, Intrinsic intrinsic)113 ScriptExecutable::ScriptExecutable(Structure* structure, VM& vm, const SourceCode& source, bool isInStrictContext, DerivedContextType derivedContextType, bool isInArrowFunctionContext, EvalContextType evalContextType, Intrinsic intrinsic) 114 114 : ExecutableBase(vm, structure, NUM_PARAMETERS_NOT_COMPILED, intrinsic) 115 115 , m_features(isInStrictContext ? StrictModeFeature : 0) … … 120 120 , m_isArrowFunctionContext(isInArrowFunctionContext) 121 121 , m_derivedContextType(static_cast<unsigned>(derivedContextType)) 122 , m_evalContextType(static_cast<unsigned>(evalContextType)) 122 123 , m_overrideLineNumber(-1) 123 124 , m_firstLine(-1) … … 395 396 const ClassInfo EvalExecutable::s_info = { "EvalExecutable", &ScriptExecutable::s_info, 0, CREATE_METHOD_TABLE(EvalExecutable) }; 396 397 397 EvalExecutable* EvalExecutable::create(ExecState* exec, const SourceCode& source, bool isInStrictContext, ThisTDZMode thisTDZMode, DerivedContextType derivedContextType, bool isArrowFunctionContext, const VariableEnvironment* variablesUnderTDZ)398 EvalExecutable* EvalExecutable::create(ExecState* exec, const SourceCode& source, bool isInStrictContext, ThisTDZMode thisTDZMode, DerivedContextType derivedContextType, bool isArrowFunctionContext, EvalContextType evalContextType, const VariableEnvironment* variablesUnderTDZ) 398 399 { 399 400 JSGlobalObject* globalObject = exec->lexicalGlobalObject(); … … 403 404 } 404 405 405 EvalExecutable* executable = new (NotNull, allocateCell<EvalExecutable>(*exec->heap())) EvalExecutable(exec, source, isInStrictContext, derivedContextType, isArrowFunctionContext );406 EvalExecutable* executable = new (NotNull, allocateCell<EvalExecutable>(*exec->heap())) EvalExecutable(exec, source, isInStrictContext, derivedContextType, isArrowFunctionContext, evalContextType); 406 407 executable->finishCreation(exec->vm()); 407 408 … … 415 416 } 416 417 417 EvalExecutable::EvalExecutable(ExecState* exec, const SourceCode& source, bool inStrictContext, DerivedContextType derivedContextType, bool isArrowFunctionContext )418 : ScriptExecutable(exec->vm().evalExecutableStructure.get(), exec->vm(), source, inStrictContext, derivedContextType, isArrowFunctionContext, NoIntrinsic)418 EvalExecutable::EvalExecutable(ExecState* exec, const SourceCode& source, bool inStrictContext, DerivedContextType derivedContextType, bool isArrowFunctionContext, EvalContextType evalContextType) 419 : ScriptExecutable(exec->vm().evalExecutableStructure.get(), exec->vm(), source, inStrictContext, derivedContextType, isArrowFunctionContext, evalContextType, NoIntrinsic) 419 420 { 420 421 } … … 428 429 429 430 ProgramExecutable::ProgramExecutable(ExecState* exec, const SourceCode& source) 430 : ScriptExecutable(exec->vm().programExecutableStructure.get(), exec->vm(), source, false, DerivedContextType::None, false, NoIntrinsic)431 : ScriptExecutable(exec->vm().programExecutableStructure.get(), exec->vm(), source, false, DerivedContextType::None, false, EvalContextType::None, NoIntrinsic) 431 432 { 432 433 m_typeProfilingStartOffset = 0; … … 444 445 445 446 ModuleProgramExecutable::ModuleProgramExecutable(ExecState* exec, const SourceCode& source) 446 : ScriptExecutable(exec->vm().moduleProgramExecutableStructure.get(), exec->vm(), source, false, DerivedContextType::None, false, NoIntrinsic)447 : ScriptExecutable(exec->vm().moduleProgramExecutableStructure.get(), exec->vm(), source, false, DerivedContextType::None, false, EvalContextType::None, NoIntrinsic) 447 448 { 448 449 m_typeProfilingStartOffset = 0; … … 476 477 477 478 FunctionExecutable::FunctionExecutable(VM& vm, const SourceCode& source, UnlinkedFunctionExecutable* unlinkedExecutable, unsigned firstLine, unsigned lastLine, unsigned startColumn, unsigned endColumn, Intrinsic intrinsic) 478 : ScriptExecutable(vm.functionExecutableStructure.get(), vm, source, unlinkedExecutable->isInStrictContext(), unlinkedExecutable->derivedContextType(), false, intrinsic)479 : ScriptExecutable(vm.functionExecutableStructure.get(), vm, source, unlinkedExecutable->isInStrictContext(), unlinkedExecutable->derivedContextType(), false, EvalContextType::None, intrinsic) 479 480 , m_unlinkedExecutable(vm, this, unlinkedExecutable) 480 481 { -
trunk/Source/JavaScriptCore/runtime/Executable.h
r198798 r198980 352 352 bool isStrictMode() const { return m_features & StrictModeFeature; } 353 353 DerivedContextType derivedContextType() const { return static_cast<DerivedContextType>(m_derivedContextType); } 354 EvalContextType evalContextType() const { return static_cast<EvalContextType>(m_evalContextType); } 354 355 355 356 ECMAMode ecmaMode() const { return isStrictMode() ? StrictMode : NotStrictMode; } … … 401 402 402 403 protected: 403 ScriptExecutable(Structure*, VM&, const SourceCode&, bool isInStrictContext, DerivedContextType, bool isInArrowFunctionContext, Intrinsic);404 ScriptExecutable(Structure*, VM&, const SourceCode&, bool isInStrictContext, DerivedContextType, bool isInArrowFunctionContext, EvalContextType, Intrinsic); 404 405 405 406 void finishCreation(VM& vm) … … 421 422 bool m_isArrowFunctionContext : 1; 422 423 unsigned m_derivedContextType : 2; // DerivedContextType 424 unsigned m_evalContextType : 2; // EvalContextType 423 425 424 426 int m_overrideLineNumber; … … 445 447 } 446 448 447 static EvalExecutable* create(ExecState*, const SourceCode&, bool isInStrictContext, ThisTDZMode, DerivedContextType, bool isArrowFunctionContext, const VariableEnvironment*);449 static EvalExecutable* create(ExecState*, const SourceCode&, bool isInStrictContext, ThisTDZMode, DerivedContextType, bool isArrowFunctionContext, EvalContextType, const VariableEnvironment*); 448 450 449 451 PassRefPtr<JITCode> generatedJITCode() … … 459 461 DECLARE_INFO; 460 462 461 ExecutableInfo executableInfo() const { return ExecutableInfo(usesEval(), isStrictMode(), false, false, ConstructorKind::None, SuperBinding::NotNeeded, SourceParseMode::ProgramMode, derivedContextType(), isArrowFunctionContext() , false); }463 ExecutableInfo executableInfo() const { return ExecutableInfo(usesEval(), isStrictMode(), false, false, ConstructorKind::None, SuperBinding::NotNeeded, SourceParseMode::ProgramMode, derivedContextType(), isArrowFunctionContext(), false, evalContextType()); } 462 464 463 465 unsigned numVariables() { return m_unlinkedEvalCodeBlock->numVariables(); } … … 468 470 friend class ScriptExecutable; 469 471 470 EvalExecutable(ExecState*, const SourceCode&, bool inStrictContext, DerivedContextType, bool isArrowFunctionContext );472 EvalExecutable(ExecState*, const SourceCode&, bool inStrictContext, DerivedContextType, bool isArrowFunctionContext, EvalContextType); 471 473 472 474 static void visitChildren(JSCell*, SlotVisitor&); … … 513 515 DECLARE_INFO; 514 516 515 ExecutableInfo executableInfo() const { return ExecutableInfo(usesEval(), isStrictMode(), false, false, ConstructorKind::None, SuperBinding::NotNeeded, SourceParseMode::ProgramMode, derivedContextType(), isArrowFunctionContext(), false ); }517 ExecutableInfo executableInfo() const { return ExecutableInfo(usesEval(), isStrictMode(), false, false, ConstructorKind::None, SuperBinding::NotNeeded, SourceParseMode::ProgramMode, derivedContextType(), isArrowFunctionContext(), false, EvalContextType::None); } 516 518 517 519 private: … … 554 556 DECLARE_INFO; 555 557 556 ExecutableInfo executableInfo() const { return ExecutableInfo(usesEval(), isStrictMode(), false, false, ConstructorKind::None, SuperBinding::NotNeeded, SourceParseMode::ModuleEvaluateMode, derivedContextType(), isArrowFunctionContext(), false ); }558 ExecutableInfo executableInfo() const { return ExecutableInfo(usesEval(), isStrictMode(), false, false, ConstructorKind::None, SuperBinding::NotNeeded, SourceParseMode::ModuleEvaluateMode, derivedContextType(), isArrowFunctionContext(), false, EvalContextType::None); } 557 559 558 560 UnlinkedModuleProgramCodeBlock* unlinkedModuleProgramCodeBlock() { return m_unlinkedModuleProgramCodeBlock.get(); } -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp
r198855 r198980 1033 1033 JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict; 1034 1034 DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff; 1035 EvalContextType evalContextType = executable->executableInfo().evalContextType(); 1036 1035 1037 ProfilerMode profilerMode = hasLegacyProfiler() ? ProfilerOn : ProfilerOff; 1036 1038 UnlinkedEvalCodeBlock* unlinkedCodeBlock = vm().codeCache()->getEvalCodeBlock( 1037 vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode, thisTDZMode, isArrowFunctionContext, debuggerMode, profilerMode, error, variablesUnderTDZ);1039 vm(), executable, executable->source(), JSParserBuiltinMode::NotBuiltin, strictMode, thisTDZMode, isArrowFunctionContext, debuggerMode, profilerMode, error, evalContextType, variablesUnderTDZ); 1038 1040 1039 1041 if (hasDebugger()) -
trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp
r197794 r198980 590 590 JSGlobalObject* calleeGlobalObject = exec->callee()->globalObject(); 591 591 VariableEnvironment emptyTDZVariables; // Indirect eval does not have access to the lexical scope. 592 EvalExecutable* eval = EvalExecutable::create(exec, makeSource(s), false, ThisTDZMode::CheckIfNeeded, DerivedContextType::None, false, &emptyTDZVariables);592 EvalExecutable* eval = EvalExecutable::create(exec, makeSource(s), false, ThisTDZMode::CheckIfNeeded, DerivedContextType::None, false, EvalContextType::None, &emptyTDZVariables); 593 593 if (!eval) 594 594 return JSValue::encode(jsUndefined()); -
trunk/Source/JavaScriptCore/tests/stress/arrowfunction-lexical-bind-newtarget.js
r197928 r198980 139 139 testCase(parentNewTarget, undefined, "Error: new.target is not lexically binded inside of the arrow function #5"); 140 140 } 141 142 143 class F { 144 constructor() { 145 let c; 146 eval('c=(()=>new.target===F)()'); 147 this.result = c; 148 } 149 getNewTargetFromEval() { 150 return eval('(()=>new.target===F)()'); 151 } 152 } 153 154 var f = new F(); 155 156 testCase(f.result, true, "Error: new.target is not lexically binded inside of the arrow function #6"); 157 testCase(f.getNewTargetFromEval(), false, "Error: new.target is not lexically binded inside of the arrow function #7"); 158 159 class G extends A { 160 constructor() { 161 var arr; 162 super(); 163 eval('arr = () => new.target'); 164 this.arrow = arr; 165 } 166 } 167 168 let g = new G(); 169 170 testCase(g.arrow(), G, "Error: new.target is not lexically binded inside of the arrow function #8"); 171 172 class H extends A { 173 constructor() { 174 var arr; 175 super(); 176 eval('arr = () => eval("(() => new.target)()")'); 177 this.arrow = arr; 178 } 179 } 180 181 let h = new H(); 182 183 testCase(h.arrow(), H, "Error: new.target is not lexically binded inside of the arrow function #9"); 184 185 class J extends A { 186 constructor() { 187 super(); 188 this.result = eval('eval("(() => new.target)()")'); 189 } 190 } 191 192 let j = new J(); 193 194 testCase(j.result, J, "Error: new.target is not lexically binded inside of the arrow function #10"); -
trunk/Source/JavaScriptCore/tests/stress/new-target.js
r197947 r198980 6 6 7 7 test(passed, true, "new.target cannot be called in global scope"); 8 9 passed = true; 10 try { 11 eval("eval(\"eval('new.target;')\")"); 12 passed = false; 13 } catch(e) { 14 passed = e instanceof SyntaxError; 15 } 16 17 test(passed, true, "new.target cannot be called in global scope"); 18 8 19 9 20 // Test without class syntax … … 63 74 test(new SuperClass().target, SuperClass, "new.target should be the same as the class constructor"); 64 75 test(new SubClass().target, SubClass, "new.target should not change when passed through super()"); 76 77 class A {} 78 79 class B extends A { 80 constructor() { 81 super(); 82 this.target = eval('new.target'); 83 } 84 } 85 86 class C extends A { 87 constructor() { 88 super(); 89 this.target = eval("eval('new.target')"); 90 } 91 } 92 93 class D extends A { 94 constructor() { 95 super(); 96 this.target = eval("eval('(function () { return new.target; })()')"); 97 } 98 } 99 100 test(new B().target, B, "new.target should be the same in eval as without eval"); 101 test(new C().target, C, "new.target should be the same in double eval as without eval"); 102 test(new D().target, undefined, "new.target should be the same in double eval as without eval"); 103 104 var newTargetInEval = function () { 105 var result; 106 var klass = function () { 107 result = eval('new.target'); 108 }; 109 klass(); 110 test(result, undefined, "new.target should be the same in eval as without eval"); 111 new klass(); 112 test(result, klass, "new.target should be the same in eval as without eval"); 113 } 114 newTargetInEval(); 115 116 var newTargetInFunctionInEval = function () { 117 var result; 118 var klass = function () { 119 result = eval('(function () { return new.target;})()'); 120 }; 121 klass(); 122 test(result, undefined, "new.target should be the same in eval as without eval"); 123 new klass(); 124 test(result, undefined, "new.target should be the same in eval as without eval"); 125 126 }; 127 newTargetInFunctionInEval();
Note: See TracChangeset
for help on using the changeset viewer.