source: webkit/trunk/JavaScriptCore/kjs/CommonIdentifiers.h@ 31119

Last change on this file since 31119 was 30871, checked in by [email protected], 17 years ago

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.
  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1/*
2 * Copyright (C) 2003,2007 Apple Computer, Inc
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef KJS_COMMON_IDENTIFIERS_H
22#define KJS_COMMON_IDENTIFIERS_H
23
24#include "identifier.h"
25#include <wtf/Noncopyable.h>
26
27// List of property names, passed to a macro so we can do set them up various
28// ways without repeating the list.
29#define KJS_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(macro) \
30 macro(arguments) \
31 macro(callee) \
32 macro(caller) \
33 macro(constructor) \
34 macro(fromCharCode) \
35 macro(global) \
36 macro(ignoreCase) \
37 macro(index) \
38 macro(input) \
39 macro(length) \
40 macro(message) \
41 macro(multiline) \
42 macro(name) \
43 macro(prototype) \
44 macro(source) \
45 macro(toExponential) \
46 macro(toFixed) \
47 macro(toLocaleString) \
48 macro(toPrecision) \
49 macro(toString) \
50 macro(valueOf) \
51 macro(eval)
52
53namespace KJS {
54
55 class CommonIdentifiers : Noncopyable {
56
57 private:
58 CommonIdentifiers();
59
60 public:
61 static CommonIdentifiers* shared();
62
63 const Identifier nullIdentifier;
64 const Identifier underscoreProto;
65
66#define KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL(name) const Identifier name;
67 KJS_COMMON_IDENTIFIERS_EACH_PROPERTY_NAME(KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL)
68#undef KJS_IDENTIFIER_DECLARE_PROPERTY_NAME_GLOBAL
69 };
70} // namespace KJS
71
72#endif // KJS_COMMON_IDENTIFIERS_H
73
Note: See TracBrowser for help on using the repository browser.