Changeset 30871 in webkit for trunk/JavaScriptCore/kjs/function.h


Ignore:
Timestamp:
Mar 7, 2008, 11:46:33 AM (17 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

Reviewed by Darin Adler.


Fixed <rdar://problem/5689093> Stricter (ES4) eval semantics


The basic rule is:


  • "eval(s)" is treated as an operator that gives the ES3 eval behavior.

... but only if there is no overriding declaration of "eval" in scope.

  • All other invocations treat eval as a function that evaluates a script in the context of its "this" object.

... but if its "this" object is not the global object it was
originally associated with, eval throws an exception.


Because only expressions of the form "eval(s)" have access to local
scope, the compiler can now statically determine whether a function
needs local scope to be dynamic.

  • kjs/nodes.h: Added FunctionCallEvalNode. It works just like FuncationCallResolveNode, except it statically indicates that the node may execute eval in the ES3 way.
  • kjs/nodes.cpp:
  • kjs/nodes2string.cpp:
  • tests/mozilla/expected.html: This patch happens to fix a Mozilla JS test, but it's a bit of a pyrrhic victory. The test intends to test Mozilla's generic API for calling eval on any object, but, in reality, we only support calling eval on the global object.

LayoutTests:

Reviewed by Darin Adler.

Tests for <rdar://problem/5689093> Stricter (ES4) eval semantics


  • fast/js/eval-cross-window-expected.txt: Added.
  • fast/js/eval-cross-window.html: Added.
  • fast/js/eval-keyword-vs-function-expected.txt: Added.
  • fast/js/eval-keyword-vs-function.html: Added.
  • fast/js/eval-overriding-expected.txt: Added.
  • fast/js/eval-overriding.html: Added.


Tests to make sure not to regress security:

  • http/tests/security/resources/xss-eval2.html: Added.
  • http/tests/security/resources/xss-eval3.html: Added.
  • http/tests/security/xss-eval-expected.txt: Added.
  • http/tests/security/xss-eval.html: Added.

I removed these tests because we no longer match the behavior they
expected, and the new tests are more comprehensive:


  • fast/js/window-eval-context-expected.txt: Removed.
  • fast/js/window-eval-context.html: Removed.
  • fast/js/window-eval-tearoff-expected.txt: Removed.
  • fast/js/window-eval-tearoff.html: Removed.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/function.h

    r30534 r30871  
    126126  class PrototypeFunction : public InternalFunctionImp {
    127127  public:
    128     typedef KJS::JSValue* (*JSMemberFunction)(ExecState*, JSObject*, const List&);
     128    typedef JSValue* (*JSMemberFunction)(ExecState*, JSObject* thisObj, const List&);
    129129
    130130    PrototypeFunction(ExecState*, int len, const Identifier&, JSMemberFunction);
     
    138138
    139139
     140  // Just like PrototypeFunction, but callbacks also get passed the JS function object.
     141  class PrototypeReflexiveFunction : public InternalFunctionImp {
     142  public:
     143    typedef JSValue* (*JSMemberFunction)(ExecState*, PrototypeReflexiveFunction*, JSObject* thisObj, const List&);
     144
     145    PrototypeReflexiveFunction(ExecState*, FunctionPrototype*, int len, const Identifier&, JSMemberFunction);
     146
     147    virtual JSValue* callAsFunction(ExecState* exec, JSObject* thisObj, const List&);
     148
     149  private:
     150    const JSMemberFunction m_function;
     151  };
     152
    140153    // Global Functions
    141     JSValue* globalFuncEval(ExecState*, JSObject*, const List&);
     154    JSValue* globalFuncEval(ExecState*, PrototypeReflexiveFunction*, JSObject*, const List&);
    142155    JSValue* globalFuncParseInt(ExecState*, JSObject*, const List&);
    143156    JSValue* globalFuncParseFloat(ExecState*, JSObject*, const List&);
     
    154167#endif
    155168
     169    JSValue* eval(ExecState*, const ScopeChain&, JSVariableObject*, JSGlobalObject*, JSObject* thisObj, const List& args);
     170
    156171    static const double mantissaOverflowLowerBound = 9007199254740992.0;
    157172    double parseIntOverflow(const char*, int length, int radix);
Note: See TracChangeset for help on using the changeset viewer.