source: webkit/trunk/JavaScriptCore/API/JSContextRef.cpp@ 28328

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

JavaScriptCore:

Reviewed by Eric Seidel.

Second step in refactoring JSGlobalObject: moved virtual functions from
Interpreter to JSGlobalObject.


Layout and JS tests pass. SunSpider reports a .7% speedup -- don't
believe his lies.

JavaScriptGlue:

Reviewed by Eric Seidel.

Updated to match the JavaScriptCore change to move virtual methods from
Interpreter to JSGlobalObject.


  • JSRun.cpp:
  • JSRun.h:
  • JSValueWrapper.cpp: (getThreadGlobalExecState):
  • JavaScriptGlue.cpp: (JSRunCopyGlobalObject): (JSRunEvaluate):

WebCore:

Reviewed by Eric Seidel.

Updated to match the JavaScriptCore change to move virtual methods from
Interpreter to JSGlobalObject.


Moved virtual ScriptInterpreter functions to Window.

WebKit/mac:

Reviewed by Eric Seidel.

Updated to match the JavaScriptCore change to move virtual methods from
Interpreter to JSGlobalObject.

  • WebView/WebFrame.mm: (-[WebFrame globalContext]): Use the toRef function instead of manually casting.
File size: 3.0 KB
Line 
1// -*- mode: c++; c-basic-offset: 4 -*-
2/*
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "config.h"
28#include "JSContextRef.h"
29
30#include "APICast.h"
31#include "JSCallbackObject.h"
32#include "JSClassRef.h"
33#include "JSGlobalObject.h"
34#include "completion.h"
35#include "interpreter.h"
36#include "object.h"
37#include <wtf/Platform.h>
38
39using namespace KJS;
40
41JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass)
42{
43 JSLock lock;
44
45 Interpreter* interpreter = new Interpreter();
46 ExecState* globalExec = &interpreter->m_globalExec;
47 JSGlobalContextRef ctx = toGlobalRef(globalExec);
48
49 if (globalObjectClass) {
50 // FIXME: ctx is not fully initialized yet, so this call to prototype() might return an object with a garbage pointer in its prototype chain.
51 JSObject* prototype = globalObjectClass->prototype(ctx);
52 JSCallbackObject<JSGlobalObject>* globalObject = new JSCallbackObject<JSGlobalObject>(globalObjectClass, prototype ? prototype : jsNull(), 0);
53 interpreter->setGlobalObject(globalObject);
54 globalObject->init(globalExec);
55 } else
56 interpreter->setGlobalObject(new JSGlobalObject());
57
58 return JSGlobalContextRetain(ctx);
59}
60
61JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx)
62{
63 JSLock lock;
64 ExecState* exec = toJS(ctx);
65 gcProtect(exec->dynamicInterpreter()->globalObject());
66 return ctx;
67}
68
69void JSGlobalContextRelease(JSGlobalContextRef ctx)
70{
71 JSLock lock;
72 ExecState* exec = toJS(ctx);
73 gcUnprotect(exec->dynamicInterpreter()->globalObject());
74}
75
76JSObjectRef JSContextGetGlobalObject(JSContextRef ctx)
77{
78 ExecState* exec = toJS(ctx);
79 return toRef(exec->dynamicInterpreter()->globalObject());
80}
Note: See TracBrowser for help on using the repository browser.