Changeset 198980 in webkit


Ignore:
Timestamp:
Apr 3, 2016 12:59:19 AM (8 years ago)
Author:
gskachkov@gmail.com
Message:

[ES6] Class syntax. Access to new.target inside of the eval should not lead to SyntaxError
https://bugs.webkit.org/show_bug.cgi?id=155545

Reviewed by Saam Barati.

Current patch allow to invoke new.target in eval if this eval is executed within function,
otherwise this will lead to Syntax error

  • bytecode/EvalCodeCache.h:

(JSC::EvalCodeCache::getSlow):

  • bytecode/ExecutableInfo.h:

(JSC::ExecutableInfo::ExecutableInfo):
(JSC::ExecutableInfo::evalContextType):

  • bytecode/UnlinkedCodeBlock.cpp:

(JSC::UnlinkedCodeBlock::UnlinkedCodeBlock):

  • bytecode/UnlinkedCodeBlock.h:

(JSC::UnlinkedCodeBlock::evalContextType):

  • bytecode/UnlinkedFunctionExecutable.cpp:

(JSC::generateUnlinkedFunctionCodeBlock):

  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::evaluate):

  • interpreter/Interpreter.cpp:

(JSC::eval):

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::Parser):
(JSC::Parser<LexerType>::parseMemberExpression):

  • parser/Parser.h:

(JSC::Scope::Scope):
(JSC::Scope::setEvalContextType):
(JSC::Scope::evalContextType):
(JSC::parse):

  • runtime/CodeCache.cpp:

(JSC::CodeCache::getGlobalCodeBlock):
(JSC::CodeCache::getProgramCodeBlock):
(JSC::CodeCache::getEvalCodeBlock):
(JSC::CodeCache::getModuleProgramCodeBlock):

  • runtime/CodeCache.h:
  • runtime/Executable.cpp:

(JSC::ScriptExecutable::ScriptExecutable):
(JSC::EvalExecutable::create):
(JSC::EvalExecutable::EvalExecutable):
(JSC::ProgramExecutable::ProgramExecutable):
(JSC::ModuleProgramExecutable::ModuleProgramExecutable):
(JSC::FunctionExecutable::FunctionExecutable):

  • runtime/Executable.h:

(JSC::ScriptExecutable::evalContextType):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::createEvalCodeBlock):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::globalFuncEval):

  • tests/stress/arrowfunction-lexical-bind-newtarget.js:
  • tests/stress/new-target.js:
Location:
trunk/Source/JavaScriptCore
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r198979 r198980  
     12016-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
    1562016-04-02  Commit Queue  <commit-queue@webkit.org>
    257
  • trunk/Source/JavaScriptCore/bytecode/EvalCodeCache.h

    r198778 r198980  
    9999        }
    100100       
    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)
    102102        {
    103103            VariableEnvironment variablesUnderTDZ;
    104104            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);
    106106            if (!evalExecutable)
    107107                return nullptr;
  • trunk/Source/JavaScriptCore/bytecode/ExecutableInfo.h

    r197043 r198980  
    3232   
    3333enum class DerivedContextType : uint8_t { None, DerivedConstructorContext, DerivedMethodContext };
     34enum class EvalContextType    : uint8_t { None, FunctionEvalContext };
    3435
    3536// FIXME: These flags, ParserModes and propagation to XXXCodeBlocks should be reorganized.
    3637// https://bugs.webkit.org/show_bug.cgi?id=151547
    3738struct 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)
    3940        : m_usesEval(usesEval)
    4041        , m_isStrictMode(isStrictMode)
     
    4748        , m_isArrowFunctionContext(isArrowFunctionContext)
    4849        , m_isClassContext(isClassContext)
     50        , m_evalContextType(static_cast<unsigned>(evalContextType))
    4951    {
    5052        ASSERT(m_constructorKind == static_cast<unsigned>(constructorKind));
     
    6062    SourceParseMode parseMode() const { return m_parseMode; }
    6163    DerivedContextType derivedContextType() const { return static_cast<DerivedContextType>(m_derivedContextType); }
     64    EvalContextType evalContextType() const { return static_cast<EvalContextType>(m_evalContextType); }
    6265    bool isArrowFunctionContext() const { return m_isArrowFunctionContext; }
    6366    bool isClassContext() const { return m_isClassContext; }
     
    7477    unsigned m_isArrowFunctionContext : 1;
    7578    unsigned m_isClassContext : 1;
     79    unsigned m_evalContextType : 2;
    7680};
    7781
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.cpp

    r197379 r198980  
    6666    , m_superBinding(static_cast<unsigned>(info.superBinding()))
    6767    , m_derivedContextType(static_cast<unsigned>(info.derivedContextType()))
     68    , m_evalContextType(static_cast<unsigned>(info.evalContextType()))
    6869    , m_isArrowFunctionContext(info.isArrowFunctionContext())
    6970    , m_isClassContext(info.isClassContext())
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedCodeBlock.h

    r197686 r198980  
    121121    bool isArrowFunction() const { return m_parseMode == SourceParseMode::ArrowFunctionMode; }
    122122    DerivedContextType derivedContextType() const { return static_cast<DerivedContextType>(m_derivedContextType); }
     123    EvalContextType evalContextType() const { return static_cast<EvalContextType>(m_evalContextType); }
    123124    bool isArrowFunctionContext() const { return m_isArrowFunctionContext; }
    124125    bool isClassContext() const { return m_isClassContext; }
     
    398399    unsigned m_superBinding : 1;
    399400    unsigned m_derivedContextType : 2;
     401    unsigned m_evalContextType : 2;
    400402    unsigned m_isArrowFunctionContext : 1;
    401403    unsigned m_isClassContext : 1;
  • trunk/Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.cpp

    r198798 r198980  
    6969    bool isClassContext = executable->superBinding() == SuperBinding::Needed;
    7070
    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));
    7372
    7473    auto generator(std::make_unique<BytecodeGenerator>(vm, function.get(), result, debuggerMode, profilerMode, executable->parentScopeTDZVariables()));
  • trunk/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp

    r194449 r198980  
    190190    ThisTDZMode thisTDZMode = codeBlock.unlinkedCodeBlock()->constructorKind() == ConstructorKind::Derived ? ThisTDZMode::AlwaysCheck : ThisTDZMode::CheckIfNeeded;
    191191
     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
    192201    VariableEnvironment variablesUnderTDZ;
    193202    JSScope::collectVariablesUnderTDZ(scope()->jsScope(), variablesUnderTDZ);
    194203
    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);
    196205    if (vm.exception()) {
    197206        exception = vm.exception();
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r198778 r198980  
    188188                : DerivedContextType::DerivedMethodContext;
    189189        }
    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
    192202        if (!eval)
    193203            return jsUndefined();
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r198928 r198980  
    192192
    193193template <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)
     194Parser<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)
    195195    : m_vm(vm)
    196196    , m_source(&source)
     
    217217    scope->setSourceParseMode(parseMode);
    218218    scope->setIsEvalContext(isEvalContext);
     219    if (isEvalContext)
     220        scope->setEvalContextType(evalContextType);
    219221   
    220222    if (derivedContextType == DerivedContextType::DerivedConstructorContext) {
     
    38603862            const Identifier* ident = m_token.m_data.ident;
    38613863            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");
    38633865                baseIsNewTarget = true;
    38643866                if (currentScope()->isArrowFunction())
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r198932 r198980  
    176176        , m_hasArguments(false)
    177177        , m_isEvalContext(false)
     178        , m_evalContextType(EvalContextType::None)
    178179        , m_constructorKind(static_cast<unsigned>(ConstructorKind::None))
    179180        , m_expectedSuperBinding(static_cast<unsigned>(SuperBinding::NotNeeded))
     
    525526    void setNeedsSuperBinding() { m_needsSuperBinding = true; }
    526527   
     528    void setEvalContextType(EvalContextType evalContextType) { m_evalContextType = evalContextType; }
     529    EvalContextType evalContextType() { return m_evalContextType; }
     530   
    527531    InnerArrowFunctionCodeFeatures innerArrowFunctionFeatures() { return m_innerArrowFunctionFeatures; }
    528532   
     
    726730    bool m_hasArguments;
    727731    bool m_isEvalContext;
     732    EvalContextType m_evalContextType;
    728733    unsigned m_constructorKind;
    729734    unsigned m_expectedSuperBinding;
     
    782787
    783788public:
    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);
    785790    ~Parser();
    786791
     
    16621667    JSParserStrictMode strictMode, SourceParseMode parseMode, SuperBinding superBinding,
    16631668    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)
    16661671{
    16671672    ASSERT(!source.provider()->source().isNull());
    16681673    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);
    16701675        std::unique_ptr<ParsedNode> result = parser.parse<ParsedNode>(error, name, parseMode);
    16711676        if (positionBeforeLastNewline)
     
    16781683    }
    16791684    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);
    16811686    std::unique_ptr<ParsedNode> result = parser.parse<ParsedNode>(error, name, parseMode);
    16821687    if (positionBeforeLastNewline)
  • trunk/Source/JavaScriptCore/runtime/CodeCache.cpp

    r198324 r198980  
    3030#include "BytecodeGenerator.h"
    3131#include "CodeSpecializationKind.h"
     32#include "ExecutableInfo.h"
    3233#include "JSCInlines.h"
    3334#include "Parser.h"
     
    8485
    8586template <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)
     87UnlinkedCodeBlockType* 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)
    8788{
    8889    SourceCodeKey key = SourceCodeKey(source, String(), CacheTypes<UnlinkedCodeBlockType>::codeType, builtinMode, strictMode, thisTDZMode);
     
    104105    DerivedContextType derivedContextType = executable->derivedContextType();
    105106    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);
    107108    if (!rootNode)
    108109        return nullptr;
     
    134135{
    135136    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
     140UnlinkedEvalCodeBlock* 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);
    142143}
    143144
     
    145146{
    146147    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);
    148149}
    149150
  • trunk/Source/JavaScriptCore/runtime/CodeCache.h

    r193766 r198980  
    2828
    2929#include "CodeSpecializationKind.h"
     30#include "ExecutableInfo.h"
    3031#include "ParserModes.h"
    3132#include "SourceCode.h"
     
    195196
    196197    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*);
    198199    UnlinkedModuleProgramCodeBlock* getModuleProgramCodeBlock(VM&, ModuleProgramExecutable*, const SourceCode&, JSParserBuiltinMode, DebuggerMode, ProfilerMode, ParserError&);
    199200    UnlinkedFunctionExecutable* getFunctionExecutableFromGlobalCode(VM&, const Identifier&, const SourceCode&, ParserError&);
     
    206207private:
    207208    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*);
    209210
    210211    CodeCacheMap m_sourceCode;
  • trunk/Source/JavaScriptCore/runtime/Executable.cpp

    r198798 r198980  
    111111const ClassInfo ScriptExecutable::s_info = { "ScriptExecutable", &ExecutableBase::s_info, 0, CREATE_METHOD_TABLE(ScriptExecutable) };
    112112
    113 ScriptExecutable::ScriptExecutable(Structure* structure, VM& vm, const SourceCode& source, bool isInStrictContext, DerivedContextType derivedContextType, bool isInArrowFunctionContext, Intrinsic intrinsic)
     113ScriptExecutable::ScriptExecutable(Structure* structure, VM& vm, const SourceCode& source, bool isInStrictContext, DerivedContextType derivedContextType, bool isInArrowFunctionContext, EvalContextType evalContextType, Intrinsic intrinsic)
    114114    : ExecutableBase(vm, structure, NUM_PARAMETERS_NOT_COMPILED, intrinsic)
    115115    , m_features(isInStrictContext ? StrictModeFeature : 0)
     
    120120    , m_isArrowFunctionContext(isInArrowFunctionContext)
    121121    , m_derivedContextType(static_cast<unsigned>(derivedContextType))
     122    , m_evalContextType(static_cast<unsigned>(evalContextType))
    122123    , m_overrideLineNumber(-1)
    123124    , m_firstLine(-1)
     
    395396const ClassInfo EvalExecutable::s_info = { "EvalExecutable", &ScriptExecutable::s_info, 0, CREATE_METHOD_TABLE(EvalExecutable) };
    396397
    397 EvalExecutable* EvalExecutable::create(ExecState* exec, const SourceCode& source, bool isInStrictContext, ThisTDZMode thisTDZMode, DerivedContextType derivedContextType, bool isArrowFunctionContext, const VariableEnvironment* variablesUnderTDZ)
     398EvalExecutable* EvalExecutable::create(ExecState* exec, const SourceCode& source, bool isInStrictContext, ThisTDZMode thisTDZMode, DerivedContextType derivedContextType, bool isArrowFunctionContext, EvalContextType evalContextType, const VariableEnvironment* variablesUnderTDZ)
    398399{
    399400    JSGlobalObject* globalObject = exec->lexicalGlobalObject();
     
    403404    }
    404405
    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);
    406407    executable->finishCreation(exec->vm());
    407408
     
    415416}
    416417
    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)
     418EvalExecutable::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)
    419420{
    420421}
     
    428429
    429430ProgramExecutable::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)
    431432{
    432433    m_typeProfilingStartOffset = 0;
     
    444445
    445446ModuleProgramExecutable::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)
    447448{
    448449    m_typeProfilingStartOffset = 0;
     
    476477
    477478FunctionExecutable::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)
    479480    , m_unlinkedExecutable(vm, this, unlinkedExecutable)
    480481{
  • trunk/Source/JavaScriptCore/runtime/Executable.h

    r198798 r198980  
    352352    bool isStrictMode() const { return m_features & StrictModeFeature; }
    353353    DerivedContextType derivedContextType() const { return static_cast<DerivedContextType>(m_derivedContextType); }
     354    EvalContextType evalContextType() const { return static_cast<EvalContextType>(m_evalContextType); }
    354355
    355356    ECMAMode ecmaMode() const { return isStrictMode() ? StrictMode : NotStrictMode; }
     
    401402
    402403protected:
    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);
    404405
    405406    void finishCreation(VM& vm)
     
    421422    bool m_isArrowFunctionContext : 1;
    422423    unsigned m_derivedContextType : 2; // DerivedContextType
     424    unsigned m_evalContextType : 2; // EvalContextType
    423425
    424426    int m_overrideLineNumber;
     
    445447    }
    446448
    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*);
    448450
    449451    PassRefPtr<JITCode> generatedJITCode()
     
    459461    DECLARE_INFO;
    460462
    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()); }
    462464
    463465    unsigned numVariables() { return m_unlinkedEvalCodeBlock->numVariables(); }
     
    468470    friend class ScriptExecutable;
    469471
    470     EvalExecutable(ExecState*, const SourceCode&, bool inStrictContext, DerivedContextType, bool isArrowFunctionContext);
     472    EvalExecutable(ExecState*, const SourceCode&, bool inStrictContext, DerivedContextType, bool isArrowFunctionContext, EvalContextType);
    471473
    472474    static void visitChildren(JSCell*, SlotVisitor&);
     
    513515    DECLARE_INFO;
    514516
    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); }
    516518
    517519private:
     
    554556    DECLARE_INFO;
    555557
    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); }
    557559
    558560    UnlinkedModuleProgramCodeBlock* unlinkedModuleProgramCodeBlock() { return m_unlinkedModuleProgramCodeBlock.get(); }
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r198855 r198980  
    10331033    JSParserStrictMode strictMode = executable->isStrictMode() ? JSParserStrictMode::Strict : JSParserStrictMode::NotStrict;
    10341034    DebuggerMode debuggerMode = hasInteractiveDebugger() ? DebuggerOn : DebuggerOff;
     1035    EvalContextType evalContextType = executable->executableInfo().evalContextType();
     1036   
    10351037    ProfilerMode profilerMode = hasLegacyProfiler() ? ProfilerOn : ProfilerOff;
    10361038    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);
    10381040
    10391041    if (hasDebugger())
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp

    r197794 r198980  
    590590    JSGlobalObject* calleeGlobalObject = exec->callee()->globalObject();
    591591    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);
    593593    if (!eval)
    594594        return JSValue::encode(jsUndefined());
  • trunk/Source/JavaScriptCore/tests/stress/arrowfunction-lexical-bind-newtarget.js

    r197928 r198980  
    139139    testCase(parentNewTarget, undefined, "Error: new.target is not lexically binded inside of the arrow function #5");
    140140}
     141
     142
     143class 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
     154var f = new F();
     155
     156testCase(f.result, true, "Error: new.target is not lexically binded inside of the arrow function #6");
     157testCase(f.getNewTargetFromEval(), false, "Error: new.target is not lexically binded inside of the arrow function #7");
     158
     159class G extends A {
     160  constructor() {
     161     var arr;
     162     super();
     163     eval('arr = () => new.target');
     164     this.arrow = arr;
     165  }
     166}
     167
     168let g = new G();
     169
     170testCase(g.arrow(), G, "Error: new.target is not lexically binded inside of the arrow function #8");
     171
     172class H extends A {
     173  constructor() {
     174     var arr;
     175     super();
     176     eval('arr = () => eval("(() => new.target)()")');
     177     this.arrow = arr;
     178  }
     179}
     180
     181let h = new H();
     182
     183testCase(h.arrow(), H, "Error: new.target is not lexically binded inside of the arrow function #9");
     184
     185class J extends A {
     186    constructor() {
     187        super();
     188        this.result = eval('eval("(() => new.target)()")');
     189    }
     190}
     191
     192let j = new J();
     193
     194testCase(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  
    66
    77test(passed, true, "new.target cannot be called in global scope");
     8
     9passed = true;
     10try {
     11    eval("eval(\"eval('new.target;')\")");
     12    passed = false;
     13} catch(e) {
     14    passed = e instanceof SyntaxError;
     15}
     16
     17test(passed, true, "new.target cannot be called in global scope");
     18
    819
    920// Test without class syntax
     
    6374test(new SuperClass().target, SuperClass, "new.target should be the same as the class constructor");
    6475test(new SubClass().target, SubClass, "new.target should not change when passed through super()");
     76
     77class A {}
     78
     79class B extends A {
     80    constructor() {
     81       super();
     82       this.target = eval('new.target');
     83    }
     84}
     85
     86class C extends A {
     87    constructor() {
     88       super();
     89       this.target = eval("eval('new.target')");
     90    }
     91}
     92
     93class D extends A {
     94    constructor() {
     95       super();
     96       this.target = eval("eval('(function () { return new.target; })()')");
     97    }
     98}
     99
     100test(new B().target, B, "new.target should be the same in eval as without eval");
     101test(new C().target, C, "new.target should be the same in double eval as without eval");
     102test(new D().target, undefined, "new.target should be the same in double eval as without eval");
     103
     104var 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}
     114newTargetInEval();
     115
     116var 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};
     127newTargetInFunctionInEval();
Note: See TracChangeset for help on using the changeset viewer.