Ignore:
Timestamp:
Jul 13, 2011, 11:59:34 AM (14 years ago)
Author:
[email protected]
Message:

https://bugs.webkit.org/show_bug.cgi?id=64424
Our direct eval behaviour deviates slightly from the spec.

Reviewed by Oliver Hunt.

Source/JavaScriptCore:

The ES5 spec defines a concept of 'Direct Call to Eval' (see section 15.1.2.1.1), where
behaviour will differ from that of an indirect call (e.g. " { eval: window.eval }.eval();"
or "var a = eval; a();" are indirect calls), particularly in non-strict scopes variables
may be introduced into the caller's environment.

ES5 direct calls are any call where the callee function is provided by a reference, a base
of that Reference is an EnvironmentRecord (this corresponds to all productions
"PrimaryExpression: Identifier", see 10.2.2.1 GetIdentifierReference), and where the name
of the reference is "eval". This means any expression of the form "eval(...)", and that
calls the standard built in eval method from on the Global Object, is considered to be
direct.

In JavaScriptCore we are currently overly restrictive. We also check that the
EnvironmentRecord that is the base of the reference is the Declaractive Environment Record
at the root of the scope chain, corresponding to the Global Object - an "eval(..)" statement
that hits a var eval in a nested scope is not considered to be direct. This behaviour does
not emanate from the spec, and is incorrect.

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::privateExecute):

  • Fixed direct eval check in op_call_eval.
  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • Fixed direct eval check in op_call_eval.
  • runtime/Executable.h:

(JSC::isHostFunction):

  • Added check for host function with specific NativeFunction.

LayoutTests:

Correct expected results.

  • fast/js/eval-keyword-vs-function-expected.txt:
  • fast/js/eval-keyword-vs-function.html:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/Executable.h

    r90437 r90938  
    515515        return static_cast<NativeExecutable*>(m_executable.get())->function();
    516516    }
     517
     518    inline bool isHostFunction(JSGlobalData& globalData, JSValue value, NativeFunction nativeFunction)
     519    {
     520        JSFunction* function = static_cast<JSFunction*>(getJSFunction(globalData, value));
     521        if (!function || !function->isHostFunction())
     522            return false;
     523        return function->nativeFunction() == nativeFunction;
     524    }
     525
    517526}
    518527
Note: See TracChangeset for help on using the changeset viewer.