source: webkit/trunk/JavaScriptCore/kjs/Context.cpp@ 26617

Last change on this file since 26617 was 25534, checked in by antti, 18 years ago

JavaScriptCore:

Reviewed by Geoff, Maciej.


Fix <rdar://problem/5445058>
REGRESSION: Unable to upload picture to eBay auction due to domain security check


eBay uses window.eval() between windows. In Firefox window.eval() switches execution
and security context to the target window, something WebKit did not do. With WebKit
security tightening in r24781, this broke picture uploads.


Fix by making WebKit switch context in window.eval().


  • kjs/Context.cpp: (KJS::Context::Context): (KJS::Context::~Context):
  • kjs/context.h: Save and restore interpreter context independently from calling context.


  • kjs/function.cpp: (KJS::GlobalFuncImp::callAsFunction): If eval is called for global object different than current one, switch execution context to that object and push it to scope.

LayoutTests:

Reviewed by Geoff, Maciej.


Test for <rdar://problem/5445058>
REGRESSION: Unable to upload picture to eBay auction due to domain security check

  • fast/js/window-eval-context-expected.txt: Added.
  • fast/js/window-eval-context.html: Added.
  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2001 Harri Porten ([email protected])
5 * Copyright (C) 2001 Peter Kelly ([email protected])
6 * Copyright (C) 2003, 2006-2007 Apple Computer, Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#include "context.h"
26
27namespace KJS {
28
29// ECMA 10.2
30Context::Context(JSObject* glob, Interpreter* interpreter, JSObject* thisV,
31 FunctionBodyNode* currentBody, CodeType type, Context* callingCon,
32 FunctionImp* func, const List* args)
33 : m_interpreter(interpreter)
34 , m_savedContext(interpreter->context())
35 , m_currentBody(currentBody)
36 , m_function(func)
37 , m_arguments(args)
38 , m_iterationDepth(0)
39 , m_switchDepth(0)
40{
41 m_codeType = type;
42 m_callingContext = callingCon;
43
44 // create and initialize activation object (ECMA 10.1.6)
45 if (type == FunctionCode || type == AnonymousCode ) {
46 m_activation = new ActivationImp(func, *args);
47 m_variable = m_activation;
48 } else {
49 m_activation = 0;
50 m_variable = glob;
51 }
52
53 // ECMA 10.2
54 switch(type) {
55 case EvalCode:
56 if (m_callingContext) {
57 scope = m_callingContext->scopeChain();
58 m_variable = m_callingContext->variableObject();
59 m_thisVal = m_callingContext->thisValue();
60 break;
61 } // else same as GlobalCode
62 case GlobalCode:
63 scope.clear();
64 scope.push(glob);
65 m_thisVal = static_cast<JSObject*>(glob);
66 break;
67 case FunctionCode:
68 case AnonymousCode:
69 if (type == FunctionCode) {
70 scope = func->scope();
71 scope.push(m_activation);
72 } else {
73 scope.clear();
74 scope.push(glob);
75 scope.push(m_activation);
76 }
77 m_variable = m_activation; // TODO: DontDelete ? (ECMA 10.2.3)
78 m_thisVal = thisV;
79 break;
80 }
81
82 m_interpreter->setContext(this);
83}
84
85Context::~Context()
86{
87 m_interpreter->setContext(m_savedContext);
88
89 // The arguments list is only needed to potentially create the arguments object,
90 // which isn't accessible from nested scopes so we can discard the list as soon
91 // as the function is done running.
92 // This prevents lists of Lists from building up, waiting to be garbage collected
93 ActivationImp* activation = static_cast<ActivationImp*>(m_activation);
94 if (activation)
95 activation->releaseArguments();
96}
97
98void Context::mark()
99{
100 for (Context* context = this; context; context = context->m_callingContext)
101 context->scope.mark();
102}
103
104} // namespace KJS
Note: See TracBrowser for help on using the repository browser.