Changeset 21027 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp


Ignore:
Timestamp:
Apr 23, 2007, 1:38:46 AM (18 years ago)
Author:
darin
Message:

JavaScriptCore:

Reviewed by Maciej.

  • fix <rdar://problem/4840688> REGRESSION (r10588, r10621): JavaScript won't parse modifications of non-references (breaks 300themovie.warnerbros.com, fedex.com)

Despite the ECMAScript specification's claim that you can treat these as syntax
errors, doing so creates some website incompatibilities. So this patch turns them back
into evaluation errors instead.

Test: fast/js/modify-non-references.html

  • kjs/grammar.y: Change makeAssignNode, makePrefixNode, and makePostfixNode so that they never fail to parse. Update rules that use them. Fix a little bit of indenting. Use new PostfixErrorNode, PrefixErrorNode, and AssignErrorNode classes.
  • kjs/nodes.h: Added an overload of throwError that takes a char* argument. Replaced setExceptionDetailsIfNeeded and debugExceptionIfNeeded with handleException, which does both. Added PostfixErrorNode, PrefixErrorNode, and AssignErrorNode classes.
  • kjs/nodes.cpp: Changed exception macros to use handleException; simpler and smaller code size than the two functions that we used before. (Node::throwError): Added the overload mentioned above. (Node::handleException): Added. Contains the code from both setExceptionDetailsIfNeeded and debugExceptionIfNeeded. (PostfixErrorNode::evaluate): Added. Throws an exception. (PrefixErrorNode::evaluate): Ditto. (AssignErrorNode::evaluate): Ditto. (ThrowNode::execute): Call handleException instead of debugExceptionIfNeeded; this effectively adds a call to setExceptionDetailsIfNeeded, which may help with getting the correct file and line number for these exceptions.
  • kjs/nodes2string.cpp: (PostfixErrorNode::streamTo): Added. (PrefixErrorNode::streamTo): Added. (AssignErrorNode::streamTo): Added.

LayoutTests:

Reviewed by Maciej.

  • test for <rdar://problem/4840688> REGRESSION (r10588, r10621): JavaScript won't parse modifications of non-references (breaks 300themovie.warnerbros.com, fedex.com)
  • fast/js/modify-non-references-expected.txt: Added.
  • fast/js/modify-non-references.html: Added.
  • fast/js/resources/modify-non-references.js: Added.
  • fast/js/assign-expected.txt: Updated for different exception text.
  • fast/js/postfix-syntax-expected.txt: Ditto.
  • fast/js/prefix-syntax-expected.txt: Ditto.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r20500 r21027  
    33 *  Copyright (C) 1999-2002 Harri Porten ([email protected])
    44 *  Copyright (C) 2001 Peter Kelly ([email protected])
    5  *  Copyright (C) 2003 Apple Computer, Inc.
     5 *  Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
    66 *
    77 *  This library is free software; you can redistribute it and/or
     
    5555#define KJS_CHECKEXCEPTION \
    5656  if (exec->hadException()) { \
    57     setExceptionDetailsIfNeeded(exec); \
    5857    JSValue *ex = exec->exception(); \
    5958    exec->clearException(); \
    60     debugExceptionIfNeeded(exec, ex); \
     59    handleException(exec, ex); \
    6160    return Completion(Throw, ex); \
    6261  } \
     
    6665#define KJS_CHECKEXCEPTIONVALUE \
    6766  if (exec->hadException()) { \
    68     setExceptionDetailsIfNeeded(exec); \
    69     debugExceptionIfNeeded(exec, exec->exception()); \
     67    handleException(exec); \
    7068    return jsUndefined(); \
    7169  } \
     
    7573#define KJS_CHECKEXCEPTIONLIST \
    7674  if (exec->hadException()) { \
    77     setExceptionDetailsIfNeeded(exec); \
    78     debugExceptionIfNeeded(exec, exec->exception()); \
     75    handleException(exec); \
    7976    return List(); \
    8077  } \
     
    222219}
    223220
     221JSValue *Node::throwError(ExecState* exec, ErrorType e, const char* msg, const char* string)
     222{
     223    UString message = msg;
     224    substitute(message, string);
     225    return KJS::throwError(exec, e, message, lineNo(), currentSourceId(exec), currentSourceURL(exec));
     226}
     227
    224228JSValue *Node::throwError(ExecState *exec, ErrorType e, const char *msg, JSValue *v, Node *expr)
    225229{
     
    269273}
    270274
    271 void Node::setExceptionDetailsIfNeeded(ExecState *exec)
    272 {
    273     JSValue *exceptionValue = exec->exception();
     275void Node::handleException(ExecState* exec)
     276{
     277    handleException(exec, exec->exception());
     278}
     279
     280void Node::handleException(ExecState* exec, JSValue* exceptionValue)
     281{
    274282    if (exceptionValue->isObject()) {
    275         JSObject *exception = static_cast<JSObject *>(exceptionValue);
     283        JSObject* exception = static_cast<JSObject*>(exceptionValue);
    276284        if (!exception->hasProperty(exec, "line") && !exception->hasProperty(exec, "sourceURL")) {
    277285            exception->put(exec, "line", jsNumber(m_line));
     
    279287        }
    280288    }
    281 }
    282 
    283 void Node::debugExceptionIfNeeded(ExecState* exec, JSValue* exceptionValue)
    284 {
    285289    Debugger* dbg = exec->dynamicInterpreter()->debugger();
    286290    if (dbg && !dbg->hasHandledException(exec, exceptionValue)) {
     
    874878}
    875879
     880// ------------------------------ PostfixErrorNode -----------------------------------
     881
     882JSValue* PostfixErrorNode::evaluate(ExecState* exec)
     883{
     884    throwError(exec, ReferenceError, "Postfix %s operator applied to value that is not a reference.",
     885        m_oper == OpPlusPlus ? "++" : "--");
     886    handleException(exec);
     887    return jsUndefined();
     888}
     889
     890// ------------------------------ DeleteResolveNode -----------------------------------
     891
    876892// ECMA 11.4.1
    877893
    878 // ------------------------------ DeleteResolveNode -----------------------------------
    879894JSValue *DeleteResolveNode::evaluate(ExecState *exec)
    880895{
     
    901916
    902917// ------------------------------ DeleteBracketNode -----------------------------------
     918
    903919JSValue *DeleteBracketNode::evaluate(ExecState *exec)
    904920{
     
    11081124
    11091125  return n2;
     1126}
     1127
     1128// ------------------------------ PrefixErrorNode -----------------------------------
     1129
     1130JSValue* PrefixErrorNode::evaluate(ExecState* exec)
     1131{
     1132    throwError(exec, ReferenceError, "Prefix %s operator applied to value that is not a reference.",
     1133        m_oper == OpPlusPlus ? "++" : "--");
     1134    handleException(exec);
     1135    return jsUndefined();
    11101136}
    11111137
     
    14671493}
    14681494
     1495// ------------------------------ AssignErrorNode -----------------------------------
     1496
     1497JSValue* AssignErrorNode::evaluate(ExecState* exec)
     1498{
     1499    throwError(exec, ReferenceError, "Left side of assignment is not a reference.");
     1500    handleException(exec);
     1501    return jsUndefined();
     1502}
     1503
    14691504// ------------------------------ AssignBracketNode -----------------------------------
    14701505
     
    22892324  KJS_CHECKEXCEPTION
    22902325
    2291   debugExceptionIfNeeded(exec, v);
    2292 
     2326  handleException(exec, v);
    22932327  return Completion(Throw, v);
    22942328}
Note: See TracChangeset for help on using the changeset viewer.