~ubuntu-branches/ubuntu/lucid/webkit/lucid-security

« back to all changes in this revision

Viewing changes to JavaScriptCore/runtime/ExceptionHelpers.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2010-01-06 21:25:06 UTC
  • mfrom: (1.2.6 upstream) (4.3.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100106212506-gd0czn4zrwf1j19l
* New upstream release
- adds basic Content-Encoding support, thanks to soup
  (Closes: #529271)
- fixes over-advertising content types as supported by
  the media player (Closes: #559420)
* debian/control:
- updated libsoup build requirement (>= 2.28.2)
* debian/libwebkit-1.0-2.symbols:
- updated with new symbols
* debian/copyright:
- updated information since 1.1.17
* Imported patch from https://bugs.webkit.org/show_bug.cgi?id=30623
- I am shipping this patch because I believe it is correct, it is the
  way to go, it fixes a race, and it needs testing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    int endOffset = 0;
78
78
    int divotPoint = 0;
79
79
    int line = codeBlock->expressionRangeForBytecodeOffset(exec, bytecodeOffset, divotPoint, startOffset, endOffset);
80
 
    UString message = "Can't find variable: ";
81
 
    message.append(ident.ustring());
82
 
    JSObject* exception = Error::create(exec, ReferenceError, message, line, codeBlock->ownerExecutable()->sourceID(), codeBlock->ownerExecutable()->sourceURL());
 
80
    JSObject* exception = Error::create(exec, ReferenceError, makeString("Can't find variable: ", ident.ustring()), line, codeBlock->ownerExecutable()->sourceID(), codeBlock->ownerExecutable()->sourceURL());
83
81
    exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
84
82
    exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);
85
83
    exception->putWithAttributes(exec, Identifier(exec, expressionEndOffsetPropertyName), jsNumber(exec, divotPoint + endOffset), ReadOnly | DontDelete);
88
86
    
89
87
static UString createErrorMessage(ExecState* exec, CodeBlock* codeBlock, int, int expressionStart, int expressionStop, JSValue value, UString error)
90
88
{
91
 
    if (!expressionStop || expressionStart > codeBlock->source()->length()) {
92
 
        UString errorText = value.toString(exec);
93
 
        errorText.append(" is ");
94
 
        errorText.append(error);
95
 
        return errorText;
96
 
    }
 
89
    if (!expressionStop || expressionStart > codeBlock->source()->length())
 
90
        return makeString(value.toString(exec), " is ", error);
 
91
    if (expressionStart < expressionStop)
 
92
        return makeString("Result of expression '", codeBlock->source()->getRange(expressionStart, expressionStop), "' [", value.toString(exec), "] is ", error, ".");
97
93
 
98
 
    UString errorText = "Result of expression ";
99
 
    
100
 
    if (expressionStart < expressionStop) {
101
 
        errorText.append('\'');
102
 
        errorText.append(codeBlock->source()->getRange(expressionStart, expressionStop));
103
 
        errorText.append("' [");
104
 
        errorText.append(value.toString(exec));
105
 
        errorText.append("] is ");
106
 
    } else {
107
 
        // No range information, so give a few characters of context
108
 
        const UChar* data = codeBlock->source()->data();
109
 
        int dataLength = codeBlock->source()->length();
110
 
        int start = expressionStart;
111
 
        int stop = expressionStart;
112
 
        // Get up to 20 characters of context to the left and right of the divot, clamping to the line.
113
 
        // then strip whitespace.
114
 
        while (start > 0 && (expressionStart - start < 20) && data[start - 1] != '\n')
115
 
            start--;
116
 
        while (start < (expressionStart - 1) && isStrWhiteSpace(data[start]))
117
 
            start++;
118
 
        while (stop < dataLength && (stop - expressionStart < 20) && data[stop] != '\n')
119
 
            stop++;
120
 
        while (stop > expressionStart && isStrWhiteSpace(data[stop]))
121
 
            stop--;
122
 
        errorText.append("near '...");
123
 
        errorText.append(codeBlock->source()->getRange(start, stop));
124
 
        errorText.append("...' [");
125
 
        errorText.append(value.toString(exec));
126
 
        errorText.append("] is ");
127
 
    }
128
 
    errorText.append(error);
129
 
    errorText.append(".");
130
 
    return errorText;
 
94
    // No range information, so give a few characters of context
 
95
    const UChar* data = codeBlock->source()->data();
 
96
    int dataLength = codeBlock->source()->length();
 
97
    int start = expressionStart;
 
98
    int stop = expressionStart;
 
99
    // Get up to 20 characters of context to the left and right of the divot, clamping to the line.
 
100
    // then strip whitespace.
 
101
    while (start > 0 && (expressionStart - start < 20) && data[start - 1] != '\n')
 
102
        start--;
 
103
    while (start < (expressionStart - 1) && isStrWhiteSpace(data[start]))
 
104
        start++;
 
105
    while (stop < dataLength && (stop - expressionStart < 20) && data[stop] != '\n')
 
106
        stop++;
 
107
    while (stop > expressionStart && isStrWhiteSpace(data[stop]))
 
108
        stop--;
 
109
    return makeString("Result of expression near '...", codeBlock->source()->getRange(start, stop), "...' [", value.toString(exec), "] is ", error, ".");
131
110
}
132
111
 
133
112
JSObject* createInvalidParamError(ExecState* exec, const char* op, JSValue value, unsigned bytecodeOffset, CodeBlock* codeBlock)
134
113
{
135
 
    UString message = "not a valid argument for '";
136
 
    message.append(op);
137
 
    message.append("'");
138
 
    
139
114
    int startOffset = 0;
140
115
    int endOffset = 0;
141
116
    int divotPoint = 0;
142
117
    int line = codeBlock->expressionRangeForBytecodeOffset(exec, bytecodeOffset, divotPoint, startOffset, endOffset);
143
 
    UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint, divotPoint + endOffset, value, message);
 
118
    UString errorMessage = createErrorMessage(exec, codeBlock, line, divotPoint, divotPoint + endOffset, value, makeString("not a valid argument for '", op, "'"));
144
119
    JSObject* exception = Error::create(exec, TypeError, errorMessage, line, codeBlock->ownerExecutable()->sourceID(), codeBlock->ownerExecutable()->sourceURL());
145
120
    exception->putWithAttributes(exec, Identifier(exec, expressionBeginOffsetPropertyName), jsNumber(exec, divotPoint - startOffset), ReadOnly | DontDelete);
146
121
    exception->putWithAttributes(exec, Identifier(exec, expressionCaretOffsetPropertyName), jsNumber(exec, divotPoint), ReadOnly | DontDelete);