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/JSGlobalObject.cpp

    r30534 r30871  
    228228    d()->URIErrorConstructor = 0;
    229229
     230    d()->evalFunction = 0;
     231
    230232    ExecState* exec = &d()->globalExec;
    231233
     
    316318    // Set global functions.
    317319
    318     putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "eval", globalFuncEval), DontEnum);
     320    d()->evalFunction = new PrototypeReflexiveFunction(exec, d()->functionPrototype, 1, exec->propertyNames().eval, globalFuncEval);
     321    putDirectFunction(d()->evalFunction, DontEnum);
    319322    putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 2, "parseInt", globalFuncParseInt), DontEnum);
    320323    putDirectFunction(new PrototypeFunction(exec, d()->functionPrototype, 1, "parseFloat", globalFuncParseFloat), DontEnum);
     
    418421    builtins._internal->URIErrorConstructor = d()->URIErrorConstructor;
    419422   
     423    builtins._internal->evalFunction = d()->evalFunction;
     424   
    420425    builtins._internal->objectPrototype = d()->objectPrototype;
    421426    builtins._internal->functionPrototype = d()->functionPrototype;
     
    455460    d()->typeErrorConstructor = builtins._internal->typeErrorConstructor;
    456461    d()->URIErrorConstructor = builtins._internal->URIErrorConstructor;
     462   
     463    d()->evalFunction = builtins._internal->evalFunction;
    457464
    458465    d()->objectPrototype = builtins._internal->objectPrototype;
     
    495502    markIfNeeded(d()->URIErrorConstructor);
    496503   
     504    markIfNeeded(d()->evalFunction);
     505   
    497506    markIfNeeded(d()->objectPrototype);
    498507    markIfNeeded(d()->functionPrototype);
Note: See TracChangeset for help on using the changeset viewer.