Ignore:
Timestamp:
Apr 30, 2017, 7:51:27 AM (8 years ago)
Author:
[email protected]
Message:

Initialize functions too early in an eval
https://bugs.webkit.org/show_bug.cgi?id=161099

Reviewed by Saam Barati.

JSTests:

  • stress/eval-func-decl-with-let-const-class.js: Added.

Source/JavaScriptCore:

Current patch allow to fix problem with scope in function that is
declared within eval. Before scope was set inside Interpretator.cpp and it
was scope where eval is executed, but in this case function would not
see let/const variables and classes declated in eval.
This patch devide declaration and binding in two operation, first just declare
variable with function name, and second bind variable to function with correct
scope

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::generate):
(JSC::BytecodeGenerator::BytecodeGenerator):

  • bytecompiler/BytecodeGenerator.h:
  • interpreter/Interpreter.cpp:

(JSC::Interpreter::execute):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r215984 r215986  
    11791179                FunctionExecutable* function = codeBlock->functionDecl(i);
    11801180                PutPropertySlot slot(variableObject);
    1181                 variableObject->methodTable()->put(variableObject, callFrame, function->name(), JSFunction::create(vm, function, scope), slot);
     1181                // We need create this variables because it will be used to emits code by bytecode generator
     1182                variableObject->methodTable()->put(variableObject, callFrame, function->name(), jsUndefined(), slot);
    11821183            }
    11831184        } else {
     
    11881189                    return checkedReturn(throwSyntaxError(callFrame, throwScope, makeString("Can't create duplicate variable in eval: '", String(function->name().impl()), "'")));
    11891190                PutPropertySlot slot(variableObject);
    1190                 variableObject->methodTable()->put(variableObject, callFrame, function->name(), JSFunction::create(vm, function, scope), slot);
     1191                // We need create this variables because it will be used to emits code by bytecode generator
     1192                variableObject->methodTable()->put(variableObject, callFrame, function->name(), jsUndefined(), slot);
    11911193                RETURN_IF_EXCEPTION(throwScope, checkedReturn(throwScope.exception()));
    11921194            }
Note: See TracChangeset for help on using the changeset viewer.