source: webkit/trunk/JavaScriptCore/runtime/JSImmediate.cpp@ 38528

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

JavaScriptCore:

2008-11-05 Gavin Barraclough <[email protected]>

Reviewed by Maciej Stachowiak.

https://bugs.webkit.org/show_bug.cgi?id=22094

Fix for bug where the callee incorrectly recieves the caller's lexical
global object as this, rather than its own. Implementation closely
follows the spec, passing jsNull, checking in the callee and replacing
with the global object where necessary.

  • VM/CTI.cpp: (JSC::CTI::compileOpCall):
  • VM/Machine.cpp: (JSC::Machine::cti_op_call_NotJSFunction): (JSC::Machine::cti_op_call_eval):
  • runtime/JSCell.h: (JSC::JSValue::toThisObject):
  • runtime/JSImmediate.cpp: (JSC::JSImmediate::toThisObject):
  • runtime/JSImmediate.h:

LayoutTests:

2008-11-05 Gavin Barraclough <[email protected]>

Reviewed by Maciej Stachowiak.

Previosly the test 'cross-site-this' checked that the second level deep method called
across frames recieved the correct this pointer, when no base object is provided.


Test updated so that it check that the code in the child frame, and both the first
and second functions called in the parent frame recieve the correct this values.

  • fast/frames/cross-site-this.html:
  • fast/frames/resources/cross-site-this-helper.html:
  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1/*
2 * Copyright (C) 2003-2006, 2008 Apple Inc. All rights reserved.
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#include "config.h"
22#include "JSImmediate.h"
23
24#include "BooleanConstructor.h"
25#include "BooleanPrototype.h"
26#include "Error.h"
27#include "ExceptionHelpers.h"
28#include "JSGlobalObject.h"
29#include "JSNotAnObject.h"
30#include "NumberConstructor.h"
31#include "NumberPrototype.h"
32
33namespace JSC {
34
35JSObject* JSImmediate::toThisObject(JSValue* v, ExecState* exec)
36{
37 ASSERT(isImmediate(v));
38 if (isNumber(v))
39 return constructNumberFromImmediateNumber(exec, v);
40 if (isBoolean(v))
41 return constructBooleanFromImmediateBoolean(exec, v);
42 if (v == jsNull())
43 return exec->globalThisValue();
44
45 JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, v->isNull());
46 exec->setException(exception);
47 return new (exec) JSNotAnObject(exec, exception);
48}
49
50JSObject* JSImmediate::toObject(JSValue* v, ExecState* exec)
51{
52 ASSERT(isImmediate(v));
53 if (isNumber(v))
54 return constructNumberFromImmediateNumber(exec, v);
55 if (isBoolean(v))
56 return constructBooleanFromImmediateBoolean(exec, v);
57
58 JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, v->isNull());
59 exec->setException(exception);
60 return new (exec) JSNotAnObject(exec, exception);
61}
62
63JSObject* JSImmediate::prototype(JSValue* v, ExecState* exec)
64{
65 ASSERT(isImmediate(v));
66 if (isNumber(v))
67 return exec->lexicalGlobalObject()->numberPrototype();
68 if (isBoolean(v))
69 return exec->lexicalGlobalObject()->booleanPrototype();
70
71 JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, v->isNull());
72 exec->setException(exception);
73 return new (exec) JSNotAnObject(exec, exception);
74}
75
76UString JSImmediate::toString(JSValue* v)
77{
78 ASSERT(isImmediate(v));
79 if (isNumber(v))
80 return UString::from(getTruncatedInt32(v));
81 if (v == jsBoolean(false))
82 return "false";
83 if (v == jsBoolean(true))
84 return "true";
85 if (v->isNull())
86 return "null";
87 ASSERT(v == jsUndefined());
88 return "undefined";
89}
90
91NEVER_INLINE double JSImmediate::nonInlineNaN()
92{
93 return std::numeric_limits<double>::quiet_NaN();
94}
95
96} // namespace JSC
Note: See TracBrowser for help on using the repository browser.