Changeset 41045 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Feb 17, 2009, 4:14:30 PM (16 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2009-02-17 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.


Fixed <rdar://problem/6595040> REGRESSION: http://www.amnestyusa.org/
fails to load.


amnestyusa.org uses the Optimist JavaScript library, which adds event
listeners by concatenating string-ified functions. This is only sure to
be syntactically valid if the string-ified functions end in semicolons.

  • parser/Lexer.cpp: (JSC::Lexer::isWhiteSpace):
  • parser/Lexer.h: (JSC::Lexer::isWhiteSpace): (JSC::Lexer::isLineTerminator): Added some helper functions for examining whitespace.
  • runtime/FunctionPrototype.cpp: (JSC::appendSemicolonIfNeeded): (JSC::functionProtoFuncToString): When string-ifying a function, insert a semicolon in the last non-whitespace position, if one doesn't already exist.

LayoutTests:

2009-02-17 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.


Test for <rdar://problem/6595040> REGRESSION: http://www.amnestyusa.org/
fails to load.

  • fast/js/function-toString-semicolon-insertion-expected.txt: Added.
  • fast/js/function-toString-semicolon-insertion.html: Added.
  • fast/js/resources/function-toString-semicolon-insertion.js: Added. (compileAndSerialize):
Location:
trunk/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r41036 r41045  
     12009-02-17  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Sam Weinig.
     4       
     5        Fixed <rdar://problem/6595040> REGRESSION: http://www.amnestyusa.org/
     6        fails to load.
     7       
     8        amnestyusa.org uses the Optimist JavaScript library, which adds event
     9        listeners by concatenating string-ified functions. This is only sure to
     10        be syntactically valid if the string-ified functions end in semicolons.
     11
     12        * parser/Lexer.cpp:
     13        (JSC::Lexer::isWhiteSpace):
     14        * parser/Lexer.h:
     15        (JSC::Lexer::isWhiteSpace):
     16        (JSC::Lexer::isLineTerminator): Added some helper functions for examining
     17        whitespace.
     18
     19        * runtime/FunctionPrototype.cpp:
     20        (JSC::appendSemicolonIfNeeded):
     21        (JSC::functionProtoFuncToString): When string-ifying a function, insert
     22        a semicolon in the last non-whitespace position, if one doesn't already exist.
     23
    1242009-02-16  Oliver Hunt  <[email protected]>
    225
  • trunk/JavaScriptCore/parser/Lexer.cpp

    r40501 r41045  
    3434#include <wtf/ASCIICType.h>
    3535#include <wtf/Assertions.h>
    36 #include <wtf/unicode/Unicode.h>
    3736
    3837using namespace WTF;
     
    590589bool Lexer::isWhiteSpace() const
    591590{
    592     return m_current == '\t' || m_current == 0x0b || m_current == 0x0c || isSeparatorSpace(m_current);
     591    return isWhiteSpace(m_current);
    593592}
    594593
  • trunk/JavaScriptCore/parser/Lexer.h

    r40214 r41045  
    2828#include "SourceCode.h"
    2929#include <wtf/Vector.h>
     30#include <wtf/unicode/Unicode.h>
    3031
    3132namespace JSC {
     
    9091        void clear();
    9192        SourceCode sourceCode(int openBrace, int closeBrace, int firstLine) { return SourceCode(m_source->provider(), openBrace, closeBrace + 1, firstLine); }
     93
     94        static inline bool isWhiteSpace(int ch)
     95        {
     96            return ch == '\t' || ch == 0x0b || ch == 0x0c || WTF::Unicode::isSeparatorSpace(ch);
     97        }
     98
     99        static inline bool isLineTerminator(int ch)
     100        {
     101            return ch == '\r' || ch == '\n' || ch == 0x2028 || ch == 0x2029;
     102        }
    92103
    93104    private:
  • trunk/JavaScriptCore/runtime/FunctionPrototype.cpp

    r40046 r41045  
    6464// Functions
    6565
     66// Compatibility hack for the Optimost JavaScript library. (See <rdar://problem/6595040>.)
     67static inline void insertSemicolonIfNeeded(UString& functionBody)
     68{
     69    ASSERT(functionBody[0] == '{');
     70    ASSERT(functionBody[functionBody.size() - 1] == '}');
     71
     72    for (size_t i = functionBody.size() - 2; i > 0; --i) {
     73        UChar ch = functionBody[i];
     74        if (!Lexer::isWhiteSpace(ch) && !Lexer::isLineTerminator(ch)) {
     75            if (ch != ';')
     76                functionBody = functionBody.substr(0, i + 1) + ";" + functionBody.substr(i + 1, functionBody.size() - (i + 1));
     77            return;
     78        }
     79    }
     80}
     81
    6682JSValuePtr functionProtoFuncToString(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&)
    6783{
    6884    if (thisValue.isObject(&JSFunction::info)) {
    6985        JSFunction* function = asFunction(thisValue);
    70         return jsString(exec, "function " + function->name(&exec->globalData()) + "(" + function->body()->paramString() + ") " + function->body()->toSourceString());
     86        UString functionBody = function->body()->toSourceString();
     87        insertSemicolonIfNeeded(functionBody);
     88        return jsString(exec, "function " + function->name(&exec->globalData()) + "(" + function->body()->paramString() + ") " + functionBody);
    7189    }
    7290
Note: See TracChangeset for help on using the changeset viewer.