summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/API
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:15 -0800
commit1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch)
tree4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /JavaScriptCore/API
parent9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff)
downloadexternal_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz
external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'JavaScriptCore/API')
-rw-r--r--JavaScriptCore/API/APICast.h63
-rw-r--r--JavaScriptCore/API/JSBase.cpp69
-rw-r--r--JavaScriptCore/API/JSBase.h31
-rw-r--r--JavaScriptCore/API/JSBasePrivate.h52
-rw-r--r--JavaScriptCore/API/JSCallbackConstructor.cpp49
-rw-r--r--JavaScriptCore/API/JSCallbackConstructor.h32
-rw-r--r--JavaScriptCore/API/JSCallbackFunction.cpp44
-rw-r--r--JavaScriptCore/API/JSCallbackFunction.h34
-rw-r--r--JavaScriptCore/API/JSCallbackObject.cpp14
-rw-r--r--JavaScriptCore/API/JSCallbackObject.h86
-rw-r--r--JavaScriptCore/API/JSCallbackObjectFunctions.h296
-rw-r--r--JavaScriptCore/API/JSClassRef.cpp168
-rw-r--r--JavaScriptCore/API/JSClassRef.h57
-rw-r--r--JavaScriptCore/API/JSContextRef.cpp80
-rw-r--r--JavaScriptCore/API/JSContextRef.h60
-rw-r--r--JavaScriptCore/API/JSObjectRef.cpp303
-rw-r--r--JavaScriptCore/API/JSObjectRef.h57
-rw-r--r--JavaScriptCore/API/JSProfilerPrivate.cpp46
-rw-r--r--JavaScriptCore/API/JSProfilerPrivate.h63
-rw-r--r--JavaScriptCore/API/JSStringRef.cpp78
-rw-r--r--JavaScriptCore/API/JSStringRef.h7
-rw-r--r--JavaScriptCore/API/JSStringRefBSTR.cpp1
-rw-r--r--JavaScriptCore/API/JSStringRefBSTR.h5
-rw-r--r--JavaScriptCore/API/JSStringRefCF.cpp29
-rw-r--r--JavaScriptCore/API/JSStringRefCF.h7
-rw-r--r--JavaScriptCore/API/JSValueRef.cpp115
-rw-r--r--JavaScriptCore/API/JSValueRef.h13
-rw-r--r--JavaScriptCore/API/JavaScript.h3
-rw-r--r--JavaScriptCore/API/JavaScriptCore.h3
-rw-r--r--JavaScriptCore/API/OpaqueJSString.cpp55
-rw-r--r--JavaScriptCore/API/OpaqueJSString.h81
-rw-r--r--JavaScriptCore/API/WebKitAvailability.h761
-rw-r--r--JavaScriptCore/API/tests/JSNode.c (renamed from JavaScriptCore/API/JSNode.c)7
-rw-r--r--JavaScriptCore/API/tests/JSNode.h (renamed from JavaScriptCore/API/JSNode.h)3
-rw-r--r--JavaScriptCore/API/tests/JSNodeList.c (renamed from JavaScriptCore/API/JSNodeList.c)3
-rw-r--r--JavaScriptCore/API/tests/JSNodeList.h (renamed from JavaScriptCore/API/JSNodeList.h)3
-rw-r--r--JavaScriptCore/API/tests/Node.c (renamed from JavaScriptCore/API/Node.c)5
-rw-r--r--JavaScriptCore/API/tests/Node.h (renamed from JavaScriptCore/API/Node.h)3
-rw-r--r--JavaScriptCore/API/tests/NodeList.c (renamed from JavaScriptCore/API/NodeList.c)9
-rw-r--r--JavaScriptCore/API/tests/NodeList.h (renamed from JavaScriptCore/API/NodeList.h)3
-rw-r--r--JavaScriptCore/API/tests/minidom.c (renamed from JavaScriptCore/API/minidom.c)16
-rw-r--r--JavaScriptCore/API/tests/minidom.html (renamed from JavaScriptCore/API/minidom.html)0
-rw-r--r--JavaScriptCore/API/tests/minidom.js (renamed from JavaScriptCore/API/minidom.js)1
-rw-r--r--JavaScriptCore/API/tests/testapi.c (renamed from JavaScriptCore/API/testapi.c)120
-rw-r--r--JavaScriptCore/API/tests/testapi.js (renamed from JavaScriptCore/API/testapi.js)2
45 files changed, 2254 insertions, 683 deletions
diff --git a/JavaScriptCore/API/APICast.h b/JavaScriptCore/API/APICast.h
index d8c7c18..ecd524c 100644
--- a/JavaScriptCore/API/APICast.h
+++ b/JavaScriptCore/API/APICast.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -30,91 +29,83 @@
#include "ustring.h"
#include "ExecState.h"
-namespace KJS {
- class ExecState;
- class JSValue;
- class JSObject;
- class PropertyNameArray;
-}
-
+typedef const struct OpaqueJSContextGroup* JSContextGroupRef;
typedef const struct OpaqueJSContext* JSContextRef;
typedef struct OpaqueJSContext* JSGlobalContextRef;
-typedef struct OpaqueJSString* JSStringRef;
typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;
typedef const struct OpaqueJSValue* JSValueRef;
typedef struct OpaqueJSValue* JSObjectRef;
/* Opaque typing convenience methods */
-inline KJS::ExecState* toJS(JSContextRef c)
+inline JSC::ExecState* toJS(JSContextRef c)
{
- return reinterpret_cast<KJS::ExecState*>(const_cast<OpaqueJSContext*>(c));
+ return reinterpret_cast<JSC::ExecState*>(const_cast<OpaqueJSContext*>(c));
}
-inline KJS::ExecState* toJS(JSGlobalContextRef c)
+inline JSC::ExecState* toJS(JSGlobalContextRef c)
{
- return reinterpret_cast<KJS::ExecState*>(c);
+ return reinterpret_cast<JSC::ExecState*>(c);
}
-inline KJS::JSValue* toJS(JSValueRef v)
+inline JSC::JSValue* toJS(JSValueRef v)
{
- return reinterpret_cast<KJS::JSValue*>(const_cast<OpaqueJSValue*>(v));
+ return reinterpret_cast<JSC::JSValue*>(const_cast<OpaqueJSValue*>(v));
}
-inline KJS::UString::Rep* toJS(JSStringRef b)
+inline JSC::JSObject* toJS(JSObjectRef o)
{
- return reinterpret_cast<KJS::UString::Rep*>(b);
+ return reinterpret_cast<JSC::JSObject*>(o);
}
-inline KJS::JSObject* toJS(JSObjectRef o)
+inline JSC::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a)
{
- return reinterpret_cast<KJS::JSObject*>(o);
+ return reinterpret_cast<JSC::PropertyNameArray*>(a);
}
-inline KJS::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a)
+inline JSC::JSGlobalData* toJS(JSContextGroupRef g)
{
- return reinterpret_cast<KJS::PropertyNameArray*>(a);
+ return reinterpret_cast<JSC::JSGlobalData*>(const_cast<OpaqueJSContextGroup*>(g));
}
-inline JSValueRef toRef(KJS::JSValue* v)
+inline JSValueRef toRef(JSC::JSValue* v)
{
return reinterpret_cast<JSValueRef>(v);
}
-inline JSValueRef* toRef(KJS::JSValue** v)
-{
- return reinterpret_cast<JSValueRef*>(const_cast<const KJS::JSValue**>(v));
-}
-
-inline JSStringRef toRef(KJS::UString::Rep* s)
+inline JSValueRef* toRef(JSC::JSValue** v)
{
- return reinterpret_cast<JSStringRef>(s);
+ return reinterpret_cast<JSValueRef*>(const_cast<const JSC::JSValue**>(v));
}
-inline JSObjectRef toRef(KJS::JSObject* o)
+inline JSObjectRef toRef(JSC::JSObject* o)
{
return reinterpret_cast<JSObjectRef>(o);
}
-inline JSObjectRef toRef(const KJS::JSObject* o)
+inline JSObjectRef toRef(const JSC::JSObject* o)
{
- return reinterpret_cast<JSObjectRef>(const_cast<KJS::JSObject*>(o));
+ return reinterpret_cast<JSObjectRef>(const_cast<JSC::JSObject*>(o));
}
-inline JSContextRef toRef(KJS::ExecState* e)
+inline JSContextRef toRef(JSC::ExecState* e)
{
return reinterpret_cast<JSContextRef>(e);
}
-inline JSGlobalContextRef toGlobalRef(KJS::ExecState* e)
+inline JSGlobalContextRef toGlobalRef(JSC::ExecState* e)
{
- ASSERT(!e->callingExecState());
return reinterpret_cast<JSGlobalContextRef>(e);
}
-inline JSPropertyNameAccumulatorRef toRef(KJS::PropertyNameArray* l)
+inline JSPropertyNameAccumulatorRef toRef(JSC::PropertyNameArray* l)
{
return reinterpret_cast<JSPropertyNameAccumulatorRef>(l);
}
+inline JSContextGroupRef toRef(JSC::JSGlobalData* g)
+{
+ return reinterpret_cast<JSContextGroupRef>(g);
+}
+
#endif // APICast_h
diff --git a/JavaScriptCore/API/JSBase.cpp b/JavaScriptCore/API/JSBase.cpp
index d8acc42..bd2935c 100644
--- a/JavaScriptCore/API/JSBase.cpp
+++ b/JavaScriptCore/API/JSBase.cpp
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
@@ -21,30 +20,38 @@
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "JSBase.h"
+#include "JSBasePrivate.h"
#include "APICast.h"
-#include <kjs/ExecState.h>
-#include <kjs/JSGlobalObject.h>
-#include <kjs/JSLock.h>
+#include "completion.h"
+#include "OpaqueJSString.h"
+#include "SourceCode.h"
+#include <runtime/ExecState.h>
+#include <runtime/InitializeThreading.h>
#include <kjs/interpreter.h>
-#include <kjs/object.h>
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSLock.h>
+#include <runtime/JSObject.h>
-using namespace KJS;
+using namespace JSC;
JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSObject* jsThisObject = toJS(thisObject);
- UString::Rep* scriptRep = toJS(script);
- UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
+
// Interpreter::evaluate sets "this" to the global object if it is NULL
- Completion completion = Interpreter::evaluate(exec->dynamicGlobalObject()->globalExec(), UString(sourceURLRep), startingLineNumber, UString(scriptRep), jsThisObject);
+ JSGlobalObject* globalObject = exec->dynamicGlobalObject();
+ SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber);
+ Completion completion = Interpreter::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), source, jsThisObject);
if (completion.complType() == Throw) {
if (exception)
@@ -61,12 +68,12 @@ JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef th
bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
- JSLock lock;
-
ExecState* exec = toJS(ctx);
- UString::Rep* scriptRep = toJS(script);
- UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
- Completion completion = Interpreter::checkSyntax(exec->dynamicGlobalObject()->globalExec(), UString(sourceURLRep), startingLineNumber, UString(scriptRep));
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber);
+ Completion completion = Interpreter::checkSyntax(exec->dynamicGlobalObject()->globalExec(), source);
if (completion.complType() == Throw) {
if (exception)
*exception = toRef(completion.value());
@@ -76,12 +83,34 @@ bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourc
return true;
}
-void JSGarbageCollect(JSContextRef)
+void JSGarbageCollect(JSContextRef ctx)
{
- JSLock lock;
- if (!Collector::isBusy())
- Collector::collect();
+ // We used to recommend passing NULL as an argument here, which caused the only heap to be collected.
+ // As there is no longer a shared heap, the previously recommended usage became a no-op (but the GC
+ // will happen when the context group is destroyed).
+ // Because the function argument was originally ignored, some clients may pass their released context here,
+ // in which case there is a risk of crashing if another thread performs GC on the same heap in between.
+ if (!ctx)
+ return;
+
+ ExecState* exec = toJS(ctx);
+ JSGlobalData& globalData = exec->globalData();
+
+ JSLock lock(globalData.isSharedInstance);
+
+ if (!globalData.heap.isBusy())
+ globalData.heap.collect();
+
// FIXME: Perhaps we should trigger a second mark and sweep
// once the garbage collector is done if this is called when
// the collector is busy.
}
+
+void JSReportExtraMemoryCost(JSContextRef ctx, size_t size)
+{
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ exec->globalData().heap.reportExtraMemoryCost(size);
+}
diff --git a/JavaScriptCore/API/JSBase.h b/JavaScriptCore/API/JSBase.h
index 7cf7c7d..f44d4ad 100644
--- a/JavaScriptCore/API/JSBase.h
+++ b/JavaScriptCore/API/JSBase.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -27,10 +26,15 @@
#ifndef JSBase_h
#define JSBase_h
+#ifndef __cplusplus
#include <stdbool.h>
+#endif
/* JavaScript engine interface */
+/*! @typedef JSContextGroupRef A group that associates JavaScript contexts with one another. Contexts in the same group may share and exchange JavaScript objects. */
+typedef const struct OpaqueJSContextGroup* JSContextGroupRef;
+
/*! @typedef JSContextRef A JavaScript execution context. Holds the global object and other execution state. */
typedef const struct OpaqueJSContext* JSContextRef;
@@ -64,8 +68,10 @@ typedef struct OpaqueJSValue* JSObjectRef;
#if defined(__GNUC__)
#define JS_EXPORT __attribute__((visibility("default")))
#elif defined(WIN32) || defined(_WIN32)
- // TODO: Export symbols with JS_EXPORT when using MSVC.
- // See http://bugs.webkit.org/show_bug.cgi?id=16227
+ /*
+ * TODO: Export symbols with JS_EXPORT when using MSVC.
+ * See http://bugs.webkit.org/show_bug.cgi?id=16227
+ */
#define JS_EXPORT
#else
#define JS_EXPORT
@@ -78,7 +84,7 @@ extern "C" {
/* Script Evaluation */
/*!
-@function
+@function JSEvaluateScript
@abstract Evaluates a string of JavaScript.
@param ctx The execution context to use.
@param script A JSString containing the script to evaluate.
@@ -103,18 +109,17 @@ JS_EXPORT JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSOb
JS_EXPORT bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
/*!
-@function
+@function JSGarbageCollect
@abstract Performs a JavaScript garbage collection.
-@param ctx This parameter is currently unused. Pass NULL.
+@param ctx The execution context to use.
@discussion JavaScript values that are on the machine stack, in a register,
protected by JSValueProtect, set as the global object of an execution context,
- or reachable from any such value will not be collected.
-
+ or reachable from any such value will not be collected.
+
During JavaScript execution, you are not required to call this function; the
- JavaScript engine will garbage collect as needed. One place you may want to call
- this function, however, is after releasing the last reference to a JSGlobalContextRef.
- At that point, a garbage collection can free the objects still referenced by the
- JSGlobalContextRef's global object, along with the global object itself.
+ JavaScript engine will garbage collect as needed. JavaScript values created
+ within a context group are automatically destroyed when the last reference
+ to the context group is released.
*/
JS_EXPORT void JSGarbageCollect(JSContextRef ctx);
@@ -122,4 +127,4 @@ JS_EXPORT void JSGarbageCollect(JSContextRef ctx);
}
#endif
-#endif // JSBase_h
+#endif /* JSBase_h */
diff --git a/JavaScriptCore/API/JSBasePrivate.h b/JavaScriptCore/API/JSBasePrivate.h
new file mode 100644
index 0000000..6beacda
--- /dev/null
+++ b/JavaScriptCore/API/JSBasePrivate.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2008 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSBasePrivate_h
+#define JSBasePrivate_h
+
+#include <JavaScriptCore/JSBase.h>
+#include <JavaScriptCore/WebKitAvailability.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*!
+@function
+@abstract Reports an object's non-GC memory payload to the garbage collector.
+@param ctx The execution context to use.
+@param size The payload's size, in bytes.
+@discussion Use this function to notify the garbage collector that a GC object
+owns a large non-GC memory region. Calling this function will encourage the
+garbage collector to collect soon, hoping to reclaim that large non-GC memory
+region.
+*/
+JS_EXPORT void JSReportExtraMemoryCost(JSContextRef ctx, size_t size) AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSBasePrivate_h */
diff --git a/JavaScriptCore/API/JSCallbackConstructor.cpp b/JavaScriptCore/API/JSCallbackConstructor.cpp
index 46c1823..29c26ea 100644
--- a/JavaScriptCore/API/JSCallbackConstructor.cpp
+++ b/JavaScriptCore/API/JSCallbackConstructor.cpp
@@ -1,6 +1,5 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,16 +27,17 @@
#include "JSCallbackConstructor.h"
#include "APICast.h"
-#include <kjs/JSGlobalObject.h>
-#include <kjs/object_object.h>
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSLock.h>
+#include <runtime/ObjectPrototype.h>
#include <wtf/Vector.h>
-namespace KJS {
+namespace JSC {
-const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0};
+const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0, 0 };
-JSCallbackConstructor::JSCallbackConstructor(ExecState* exec, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback)
- : JSObject(exec->lexicalGlobalObject()->objectPrototype())
+JSCallbackConstructor::JSCallbackConstructor(PassRefPtr<StructureID> structure, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback)
+ : JSObject(structure)
, m_class(jsClass)
, m_callback(callback)
{
@@ -51,32 +51,29 @@ JSCallbackConstructor::~JSCallbackConstructor()
JSClassRelease(m_class);
}
-bool JSCallbackConstructor::implementsHasInstance() const
-{
- return true;
-}
-
-bool JSCallbackConstructor::implementsConstruct() const
-{
- return true;
-}
-
-JSObject* JSCallbackConstructor::construct(ExecState* exec, const List &args)
+static JSObject* constructJSCallback(ExecState* exec, JSObject* constructor, const ArgList& args)
{
JSContextRef ctx = toRef(exec);
- JSObjectRef thisRef = toRef(this);
+ JSObjectRef constructorRef = toRef(constructor);
- if (m_callback) {
+ JSObjectCallAsConstructorCallback callback = static_cast<JSCallbackConstructor*>(constructor)->callback();
+ if (callback) {
int argumentCount = static_cast<int>(args.size());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
- arguments[i] = toRef(args[i]);
+ arguments[i] = toRef(args.at(exec, i));
- JSLock::DropAllLocks dropAllLocks;
- return toJS(m_callback(ctx, thisRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
+ JSLock::DropAllLocks dropAllLocks(exec);
+ return toJS(callback(ctx, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
}
- return toJS(JSObjectMake(ctx, m_class, 0));
+ return toJS(JSObjectMake(ctx, static_cast<JSCallbackConstructor*>(constructor)->classRef(), 0));
+}
+
+ConstructType JSCallbackConstructor::getConstructData(ConstructData& constructData)
+{
+ constructData.native.function = constructJSCallback;
+ return ConstructTypeHost;
}
-} // namespace KJS
+} // namespace JSC
diff --git a/JavaScriptCore/API/JSCallbackConstructor.h b/JavaScriptCore/API/JSCallbackConstructor.h
index fc45cb5..01f15a8 100644
--- a/JavaScriptCore/API/JSCallbackConstructor.h
+++ b/JavaScriptCore/API/JSCallbackConstructor.h
@@ -1,6 +1,5 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
- * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,32 +27,31 @@
#define JSCallbackConstructor_h
#include "JSObjectRef.h"
-#include <kjs/object.h>
+#include <runtime/JSObject.h>
-namespace KJS {
+namespace JSC {
-class JSCallbackConstructor : public JSObject
-{
+class JSCallbackConstructor : public JSObject {
public:
- JSCallbackConstructor(ExecState* exec, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback);
+ JSCallbackConstructor(PassRefPtr<StructureID>, JSClassRef, JSObjectCallAsConstructorCallback);
virtual ~JSCallbackConstructor();
-
- virtual bool implementsHasInstance() const;
-
- virtual bool implementsConstruct() const;
- virtual JSObject* construct(ExecState*, const List &args);
-
- virtual const ClassInfo *classInfo() const { return &info; }
+ JSClassRef classRef() const { return m_class; }
+ JSObjectCallAsConstructorCallback callback() const { return m_callback; }
static const ClassInfo info;
+ static PassRefPtr<StructureID> createStructureID(JSValue* proto)
+ {
+ return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance | HasStandardGetOwnPropertySlot));
+ }
+
private:
- JSCallbackConstructor(); // prevent default construction
- JSCallbackConstructor(const JSCallbackConstructor&);
+ virtual ConstructType getConstructData(ConstructData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
JSClassRef m_class;
JSObjectCallAsConstructorCallback m_callback;
};
-} // namespace KJS
+} // namespace JSC
#endif // JSCallbackConstructor_h
diff --git a/JavaScriptCore/API/JSCallbackFunction.cpp b/JavaScriptCore/API/JSCallbackFunction.cpp
index fb3937d..45d726a 100644
--- a/JavaScriptCore/API/JSCallbackFunction.cpp
+++ b/JavaScriptCore/API/JSCallbackFunction.cpp
@@ -1,6 +1,5 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
- * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,40 +28,43 @@
#include "JSCallbackFunction.h"
#include "APICast.h"
-#include "function.h"
-#include "function_object.h"
-#include <kjs/JSGlobalObject.h>
+#include "JSFunction.h"
+#include "FunctionPrototype.h"
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSLock.h>
#include <wtf/Vector.h>
-namespace KJS {
+namespace JSC {
-const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunctionImp::info, 0};
+ASSERT_CLASS_FITS_IN_CELL(JSCallbackFunction);
+
+const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunction::info, 0, 0 };
JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name)
- : InternalFunctionImp(exec->lexicalGlobalObject()->functionPrototype(), name)
+ : InternalFunction(&exec->globalData(), exec->lexicalGlobalObject()->callbackFunctionStructure(), name)
, m_callback(callback)
{
}
-// InternalFunctionImp mish-mashes constructor and function behavior -- we should
-// refactor the code so this override isn't necessary
-bool JSCallbackFunction::implementsHasInstance() const {
- return false;
-}
-
-JSValue* JSCallbackFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List &args)
+JSValue* JSCallbackFunction::call(ExecState* exec, JSObject* functionObject, JSValue* thisValue, const ArgList& args)
{
JSContextRef execRef = toRef(exec);
- JSObjectRef thisRef = toRef(this);
- JSObjectRef thisObjRef = toRef(thisObj);
+ JSObjectRef functionRef = toRef(functionObject);
+ JSObjectRef thisObjRef = toRef(thisValue->toThisObject(exec));
int argumentCount = static_cast<int>(args.size());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
- arguments[i] = toRef(args[i]);
+ arguments[i] = toRef(args.at(exec, i));
- JSLock::DropAllLocks dropAllLocks;
- return toJS(m_callback(execRef, thisRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
+ JSLock::DropAllLocks dropAllLocks(exec);
+ return toJS(static_cast<JSCallbackFunction*>(functionObject)->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
+}
+
+CallType JSCallbackFunction::getCallData(CallData& callData)
+{
+ callData.native.function = call;
+ return CallTypeHost;
}
-} // namespace KJS
+} // namespace JSC
diff --git a/JavaScriptCore/API/JSCallbackFunction.h b/JavaScriptCore/API/JSCallbackFunction.h
index 48be3d2..806a992 100644
--- a/JavaScriptCore/API/JSCallbackFunction.h
+++ b/JavaScriptCore/API/JSCallbackFunction.h
@@ -1,6 +1,5 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
- * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,30 +26,33 @@
#ifndef JSCallbackFunction_h
#define JSCallbackFunction_h
+#include "InternalFunction.h"
#include "JSObjectRef.h"
-#include "function.h"
-#include "object.h"
-namespace KJS {
+namespace JSC {
-class JSCallbackFunction : public InternalFunctionImp
-{
+class JSCallbackFunction : public InternalFunction {
public:
- JSCallbackFunction(ExecState* exec, JSObjectCallAsFunctionCallback callback, const Identifier& name);
+ JSCallbackFunction(ExecState*, JSObjectCallAsFunctionCallback, const Identifier& name);
- virtual bool implementsHasInstance() const;
- virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List &args);
-
- virtual const ClassInfo *classInfo() const { return &info; }
static const ClassInfo info;
+ // InternalFunction mish-mashes constructor and function behavior -- we should
+ // refactor the code so this override isn't necessary
+ static PassRefPtr<StructureID> createStructureID(JSValue* proto)
+ {
+ return StructureID::create(proto, TypeInfo(ObjectType, HasStandardGetOwnPropertySlot));
+ }
+
private:
- JSCallbackFunction(); // prevent default construction
- JSCallbackFunction(const JSCallbackFunction&);
-
+ virtual CallType getCallData(CallData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ static JSValue* call(ExecState*, JSObject*, JSValue*, const ArgList&);
+
JSObjectCallAsFunctionCallback m_callback;
};
-} // namespace KJS
+} // namespace JSC
#endif // JSCallbackFunction_h
diff --git a/JavaScriptCore/API/JSCallbackObject.cpp b/JavaScriptCore/API/JSCallbackObject.cpp
index 129b304..4be35bd 100644
--- a/JavaScriptCore/API/JSCallbackObject.cpp
+++ b/JavaScriptCore/API/JSCallbackObject.cpp
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2007 Eric Seidel <eric@webkit.org>
@@ -30,12 +29,13 @@
#include "collector.h"
-namespace KJS {
+namespace JSC {
-// Define the two types of JSCallbackObjects we support.
-template <> const ClassInfo JSCallbackObject<JSObject>::info = { "CallbackObject", 0, 0 };
-template <> const ClassInfo JSCallbackObject<JSGlobalObject>::info = { "CallbackGlobalObject", 0, 0 };
+ASSERT_CLASS_FITS_IN_CELL(JSCallbackObject<JSObject>);
+ASSERT_CLASS_FITS_IN_CELL(JSCallbackObject<JSGlobalObject>);
-COMPILE_ASSERT(sizeof(JSCallbackObject<JSGlobalObject>) <= CELL_SIZE, global_callback_object_fits_in_cell);
+// Define the two types of JSCallbackObjects we support.
+template <> const ClassInfo JSCallbackObject<JSObject>::info = { "CallbackObject", 0, 0, 0 };
+template <> const ClassInfo JSCallbackObject<JSGlobalObject>::info = { "CallbackGlobalObject", 0, 0, 0 };
-} // namespace KJS
+} // namespace JSC
diff --git a/JavaScriptCore/API/JSCallbackObject.h b/JavaScriptCore/API/JSCallbackObject.h
index 7eb32a6..7543e17 100644
--- a/JavaScriptCore/API/JSCallbackObject.h
+++ b/JavaScriptCore/API/JSCallbackObject.h
@@ -1,6 +1,5 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
- * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2007 Eric Seidel <eric@webkit.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -30,64 +29,85 @@
#include "JSObjectRef.h"
#include "JSValueRef.h"
-#include "object.h"
+#include "JSObject.h"
-namespace KJS {
+namespace JSC {
template <class Base>
-class JSCallbackObject : public Base
-{
+class JSCallbackObject : public Base {
public:
- JSCallbackObject(ExecState*, JSClassRef, JSValue* prototype, void* data);
+ JSCallbackObject(ExecState*, PassRefPtr<StructureID>, JSClassRef, void* data);
JSCallbackObject(JSClassRef);
virtual ~JSCallbackObject();
+ void setPrivate(void* data);
+ void* getPrivate();
+
+ static const ClassInfo info;
+
+ JSClassRef classRef() const { return m_callbackObjectData->jsClass; }
+ bool inherits(JSClassRef) const;
+
+ static PassRefPtr<StructureID> createStructureID(JSValue* proto)
+ {
+ return StructureID::create(proto, TypeInfo(ObjectType, ImplementsHasInstance | OverridesHasInstance));
+ }
+
+private:
virtual UString className() const;
virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
virtual bool getOwnPropertySlot(ExecState*, unsigned, PropertySlot&);
- virtual void put(ExecState*, const Identifier&, JSValue*, int attr);
- virtual void put(ExecState*, unsigned, JSValue*, int attr);
+ virtual void put(ExecState*, const Identifier&, JSValue*, PutPropertySlot&);
virtual bool deleteProperty(ExecState*, const Identifier&);
virtual bool deleteProperty(ExecState*, unsigned);
- virtual bool implementsConstruct() const;
- virtual JSObject* construct(ExecState*, const List& args);
-
- virtual bool implementsHasInstance() const;
- virtual bool hasInstance(ExecState *exec, JSValue *value);
-
- virtual bool implementsCall() const;
- virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List &args);
+ virtual bool hasInstance(ExecState* exec, JSValue* value, JSValue* proto);
virtual void getPropertyNames(ExecState*, PropertyNameArray&);
virtual double toNumber(ExecState*) const;
virtual UString toString(ExecState*) const;
- void setPrivate(void* data);
- void* getPrivate();
-
- virtual const ClassInfo *classInfo() const { return &info; }
- static const ClassInfo info;
+ virtual ConstructType getConstructData(ConstructData&);
+ virtual CallType getCallData(CallData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
- bool inherits(JSClassRef) const;
-
-private:
void init(ExecState*);
+
+ static JSCallbackObject* asCallbackObject(JSValue*);
+
+ static JSValue* call(ExecState*, JSObject* functionObject, JSValue* thisValue, const ArgList&);
+ static JSObject* construct(ExecState*, JSObject* constructor, const ArgList&);
+
+ static JSValue* cachedValueGetter(ExecState*, const Identifier&, const PropertySlot&);
+ static JSValue* staticValueGetter(ExecState*, const Identifier&, const PropertySlot&);
+ static JSValue* staticFunctionGetter(ExecState*, const Identifier&, const PropertySlot&);
+ static JSValue* callbackGetter(ExecState*, const Identifier&, const PropertySlot&);
+
+ struct JSCallbackObjectData {
+ JSCallbackObjectData(void* privateData, JSClassRef jsClass)
+ : privateData(privateData)
+ , jsClass(jsClass)
+ {
+ JSClassRetain(jsClass);
+ }
+
+ ~JSCallbackObjectData()
+ {
+ JSClassRelease(jsClass);
+ }
+
+ void* privateData;
+ JSClassRef jsClass;
+ };
- static JSValue* cachedValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
- static JSValue* staticValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot);
- static JSValue* staticFunctionGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot);
- static JSValue* callbackGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
-
- void* m_privateData;
- JSClassRef m_class;
+ OwnPtr<JSCallbackObjectData> m_callbackObjectData;
};
-} // namespace KJS
+} // namespace JSC
// include the actual template class implementation
#include "JSCallbackObjectFunctions.h"
diff --git a/JavaScriptCore/API/JSCallbackObjectFunctions.h b/JavaScriptCore/API/JSCallbackObjectFunctions.h
index f987dd8..f008987 100644
--- a/JavaScriptCore/API/JSCallbackObjectFunctions.h
+++ b/JavaScriptCore/API/JSCallbackObjectFunctions.h
@@ -1,6 +1,5 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
- * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2007 Eric Seidel <eric@webkit.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -25,33 +24,42 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <wtf/Platform.h>
#include "APICast.h"
+#include "Error.h"
#include "JSCallbackFunction.h"
#include "JSClassRef.h"
-#include "JSObjectRef.h"
#include "JSGlobalObject.h"
+#include "JSLock.h"
+#include "JSObjectRef.h"
+#include "JSString.h"
#include "JSStringRef.h"
+#include "OpaqueJSString.h"
#include "PropertyNameArray.h"
-#include "internal.h"
#include <wtf/Vector.h>
-namespace KJS {
+namespace JSC {
+
+template <class Base>
+inline JSCallbackObject<Base>* JSCallbackObject<Base>::asCallbackObject(JSValue* value)
+{
+ ASSERT(asObject(value)->inherits(&info));
+ return static_cast<JSCallbackObject*>(asObject(value));
+}
template <class Base>
-JSCallbackObject<Base>::JSCallbackObject(ExecState* exec, JSClassRef jsClass, JSValue* prototype, void* data)
- : Base(prototype)
- , m_privateData(data)
- , m_class(JSClassRetain(jsClass))
+JSCallbackObject<Base>::JSCallbackObject(ExecState* exec, PassRefPtr<StructureID> structure, JSClassRef jsClass, void* data)
+ : Base(structure)
+ , m_callbackObjectData(new JSCallbackObjectData(data, jsClass))
{
init(exec);
}
-// Global object constructor. FIXME: Move this into a JSGlobalCallbackObject subclass.
+// Global object constructor.
+// FIXME: Move this into a separate JSGlobalCallbackObject class derived from this one.
template <class Base>
JSCallbackObject<Base>::JSCallbackObject(JSClassRef jsClass)
- : m_privateData(0)
- , m_class(JSClassRetain(jsClass))
+ : Base()
+ , m_callbackObjectData(new JSCallbackObjectData(0, jsClass))
{
ASSERT(Base::isGlobalObject());
init(static_cast<JSGlobalObject*>(this)->globalExec());
@@ -63,7 +71,7 @@ void JSCallbackObject<Base>::init(ExecState* exec)
ASSERT(exec);
Vector<JSObjectInitializeCallback, 16> initRoutines;
- JSClassRef jsClass = m_class;
+ JSClassRef jsClass = classRef();
do {
if (JSObjectInitializeCallback initialize = jsClass->initialize)
initRoutines.append(initialize);
@@ -71,7 +79,7 @@ void JSCallbackObject<Base>::init(ExecState* exec)
// initialize from base to derived
for (int i = static_cast<int>(initRoutines.size()) - 1; i >= 0; i--) {
- JSLock::DropAllLocks dropAllLocks;
+ JSLock::DropAllLocks dropAllLocks(exec);
JSObjectInitializeCallback initialize = initRoutines[i];
initialize(toRef(exec), toRef(this));
}
@@ -82,19 +90,17 @@ JSCallbackObject<Base>::~JSCallbackObject()
{
JSObjectRef thisRef = toRef(this);
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
- if (JSObjectFinalizeCallback finalize = jsClass->finalize) {
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (JSObjectFinalizeCallback finalize = jsClass->finalize)
finalize(thisRef);
- }
-
- JSClassRelease(m_class);
}
template <class Base>
UString JSCallbackObject<Base>::className() const
{
- if (!m_class->className.isNull())
- return m_class->className;
+ UString thisClassName = classRef()->className();
+ if (!thisClassName.isNull())
+ return thisClassName;
return Base::className();
}
@@ -104,35 +110,39 @@ bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, const Identifie
{
JSContextRef ctx = toRef(exec);
JSObjectRef thisRef = toRef(this);
- JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
+ RefPtr<OpaqueJSString> propertyNameRef;
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
// optional optimization to bypass getProperty in cases when we only need to know if the property exists
if (JSObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
- JSLock::DropAllLocks dropAllLocks;
- if (hasProperty(ctx, thisRef, propertyNameRef)) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (hasProperty(ctx, thisRef, propertyNameRef.get())) {
slot.setCustom(this, callbackGetter);
return true;
}
} else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
- JSLock::DropAllLocks dropAllLocks;
- if (JSValueRef value = getProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot()))) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (JSValueRef value = getProperty(ctx, thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot()))) {
// cache the value so we don't have to compute it again
// FIXME: This violates the PropertySlot design a little bit.
// We should either use this optimization everywhere, or nowhere.
- slot.setCustom(reinterpret_cast<JSObject*>(toJS(value)), cachedValueGetter);
+ slot.setCustom(asObject(toJS(value)), cachedValueGetter);
return true;
}
}
- if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
if (staticValues->contains(propertyName.ustring().rep())) {
slot.setCustom(this, staticValueGetter);
return true;
}
}
- if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
if (staticFunctions->contains(propertyName.ustring().rep())) {
slot.setCustom(this, staticFunctionGetter);
return true;
@@ -146,54 +156,52 @@ bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, const Identifie
template <class Base>
bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
{
- return getOwnPropertySlot(exec, Identifier::from(propertyName), slot);
+ return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
}
template <class Base>
-void JSCallbackObject<Base>::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr)
+void JSCallbackObject<Base>::put(ExecState* exec, const Identifier& propertyName, JSValue* value, PutPropertySlot& slot)
{
JSContextRef ctx = toRef(exec);
JSObjectRef thisRef = toRef(this);
- JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
+ RefPtr<OpaqueJSString> propertyNameRef;
JSValueRef valueRef = toRef(value);
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
- JSLock::DropAllLocks dropAllLocks;
- if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, toRef(exec->exceptionSlot())))
return;
}
- if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
if (entry->attributes & kJSPropertyAttributeReadOnly)
return;
if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
- JSLock::DropAllLocks dropAllLocks;
- if (setProperty(ctx, thisRef, propertyNameRef, valueRef, toRef(exec->exceptionSlot())))
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, toRef(exec->exceptionSlot())))
return;
} else
throwError(exec, ReferenceError, "Attempt to set a property that is not settable.");
}
}
- if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
if (entry->attributes & kJSPropertyAttributeReadOnly)
return;
- JSCallbackObject<Base>::putDirect(propertyName, value, attr); // put as override property
+ JSCallbackObject<Base>::putDirect(propertyName, value); // put as override property
return;
}
}
}
- return Base::put(exec, propertyName, value, attr);
-}
-
-template <class Base>
-void JSCallbackObject<Base>::put(ExecState* exec, unsigned propertyName, JSValue* value, int attr)
-{
- return put(exec, Identifier::from(propertyName), value, attr);
+ return Base::put(exec, propertyName, value, slot);
}
template <class Base>
@@ -201,16 +209,18 @@ bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, const Identifier& p
{
JSContextRef ctx = toRef(exec);
JSObjectRef thisRef = toRef(this);
- JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
+ RefPtr<OpaqueJSString> propertyNameRef;
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
- JSLock::DropAllLocks dropAllLocks;
- if (deleteProperty(ctx, thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (deleteProperty(ctx, thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
return true;
}
- if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
if (entry->attributes & kJSPropertyAttributeDontDelete)
return false;
@@ -218,7 +228,7 @@ bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, const Identifier& p
}
}
- if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
if (entry->attributes & kJSPropertyAttributeDontDelete)
return false;
@@ -233,97 +243,89 @@ bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, const Identifier& p
template <class Base>
bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, unsigned propertyName)
{
- return deleteProperty(exec, Identifier::from(propertyName));
+ return deleteProperty(exec, Identifier::from(exec, propertyName));
}
template <class Base>
-bool JSCallbackObject<Base>::implementsConstruct() const
+ConstructType JSCallbackObject<Base>::getConstructData(ConstructData& constructData)
{
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
- if (jsClass->callAsConstructor)
- return true;
-
- return false;
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (jsClass->callAsConstructor) {
+ constructData.native.function = construct;
+ return ConstructTypeHost;
+ }
+ }
+ return ConstructTypeNone;
}
template <class Base>
-JSObject* JSCallbackObject<Base>::construct(ExecState* exec, const List& args)
+JSObject* JSCallbackObject<Base>::construct(ExecState* exec, JSObject* constructor, const ArgList& args)
{
JSContextRef execRef = toRef(exec);
- JSObjectRef thisRef = toRef(this);
+ JSObjectRef constructorRef = toRef(constructor);
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
+ for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) {
if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {
int argumentCount = static_cast<int>(args.size());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
- arguments[i] = toRef(args[i]);
- JSLock::DropAllLocks dropAllLocks;
- return toJS(callAsConstructor(execRef, thisRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
+ arguments[i] = toRef(args.at(exec, i));
+ JSLock::DropAllLocks dropAllLocks(exec);
+ return toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
}
}
- ASSERT(0); // implementsConstruct should prevent us from reaching here
+ ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here
return 0;
}
template <class Base>
-bool JSCallbackObject<Base>::implementsHasInstance() const
-{
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
- if (jsClass->hasInstance)
- return true;
-
- return false;
-}
-
-template <class Base>
-bool JSCallbackObject<Base>::hasInstance(ExecState *exec, JSValue *value)
+bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValue* value, JSValue*)
{
JSContextRef execRef = toRef(exec);
JSObjectRef thisRef = toRef(this);
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) {
- JSLock::DropAllLocks dropAllLocks;
+ JSLock::DropAllLocks dropAllLocks(exec);
return hasInstance(execRef, thisRef, toRef(value), toRef(exec->exceptionSlot()));
}
-
- ASSERT_NOT_REACHED(); // implementsHasInstance should prevent us from reaching here
- return 0;
+ }
+ return false;
}
-
template <class Base>
-bool JSCallbackObject<Base>::implementsCall() const
+CallType JSCallbackObject<Base>::getCallData(CallData& callData)
{
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
- if (jsClass->callAsFunction)
- return true;
-
- return false;
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (jsClass->callAsFunction) {
+ callData.native.function = call;
+ return CallTypeHost;
+ }
+ }
+ return CallTypeNone;
}
template <class Base>
-JSValue* JSCallbackObject<Base>::callAsFunction(ExecState* exec, JSObject* thisObj, const List &args)
+JSValue* JSCallbackObject<Base>::call(ExecState* exec, JSObject* functionObject, JSValue* thisValue, const ArgList& args)
{
JSContextRef execRef = toRef(exec);
- JSObjectRef thisRef = toRef(this);
- JSObjectRef thisObjRef = toRef(thisObj);
+ JSObjectRef functionRef = toRef(functionObject);
+ JSObjectRef thisObjRef = toRef(thisValue->toThisObject(exec));
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
+ for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(functionObject)->classRef(); jsClass; jsClass = jsClass->parentClass) {
if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) {
int argumentCount = static_cast<int>(args.size());
Vector<JSValueRef, 16> arguments(argumentCount);
for (int i = 0; i < argumentCount; i++)
- arguments[i] = toRef(args[i]);
- JSLock::DropAllLocks dropAllLocks;
- return toJS(callAsFunction(execRef, thisRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
+ arguments[i] = toRef(args.at(exec, i));
+ JSLock::DropAllLocks dropAllLocks(exec);
+ return toJS(callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), toRef(exec->exceptionSlot())));
}
}
- ASSERT_NOT_REACHED(); // implementsCall should prevent us from reaching here
- return 0;
+ ASSERT_NOT_REACHED(); // getCallData should prevent us from reaching here
+ return noValue();
}
template <class Base>
@@ -332,31 +334,31 @@ void JSCallbackObject<Base>::getPropertyNames(ExecState* exec, PropertyNameArray
JSContextRef execRef = toRef(exec);
JSObjectRef thisRef = toRef(this);
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass) {
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
if (JSObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames) {
- JSLock::DropAllLocks dropAllLocks;
+ JSLock::DropAllLocks dropAllLocks(exec);
getPropertyNames(execRef, thisRef, toRef(&propertyNames));
}
- if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues) {
- typedef OpaqueJSClass::StaticValuesTable::const_iterator iterator;
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ typedef OpaqueJSClassStaticValuesTable::const_iterator iterator;
iterator end = staticValues->end();
for (iterator it = staticValues->begin(); it != end; ++it) {
UString::Rep* name = it->first.get();
StaticValueEntry* entry = it->second;
if (entry->getProperty && !(entry->attributes & kJSPropertyAttributeDontEnum))
- propertyNames.add(Identifier(name));
+ propertyNames.add(Identifier(exec, name));
}
}
- if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
- typedef OpaqueJSClass::StaticFunctionsTable::const_iterator iterator;
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ typedef OpaqueJSClassStaticFunctionsTable::const_iterator iterator;
iterator end = staticFunctions->end();
for (iterator it = staticFunctions->begin(); it != end; ++it) {
UString::Rep* name = it->first.get();
StaticFunctionEntry* entry = it->second;
if (!(entry->attributes & kJSPropertyAttributeDontEnum))
- propertyNames.add(Identifier(name));
+ propertyNames.add(Identifier(exec, name));
}
}
}
@@ -367,12 +369,17 @@ void JSCallbackObject<Base>::getPropertyNames(ExecState* exec, PropertyNameArray
template <class Base>
double JSCallbackObject<Base>::toNumber(ExecState* exec) const
{
+ // We need this check to guard against the case where this object is rhs of
+ // a binary expression where lhs threw an exception in its conversion to
+ // primitive
+ if (exec->hadException())
+ return NaN;
JSContextRef ctx = toRef(exec);
JSObjectRef thisRef = toRef(this);
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
- JSLock::DropAllLocks dropAllLocks;
+ JSLock::DropAllLocks dropAllLocks(exec);
if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeNumber, toRef(exec->exceptionSlot())))
return toJS(value)->getNumber();
}
@@ -386,10 +393,14 @@ UString JSCallbackObject<Base>::toString(ExecState* exec) const
JSContextRef ctx = toRef(exec);
JSObjectRef thisRef = toRef(this);
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
- JSLock::DropAllLocks dropAllLocks;
- if (JSValueRef value = convertToType(ctx, thisRef, kJSTypeString, toRef(exec->exceptionSlot())))
+ JSValueRef value;
+ {
+ JSLock::DropAllLocks dropAllLocks(exec);
+ value = convertToType(ctx, thisRef, kJSTypeString, toRef(exec->exceptionSlot()));
+ }
+ if (value)
return toJS(value)->getString();
}
@@ -399,19 +410,19 @@ UString JSCallbackObject<Base>::toString(ExecState* exec) const
template <class Base>
void JSCallbackObject<Base>::setPrivate(void* data)
{
- m_privateData = data;
+ m_callbackObjectData->privateData = data;
}
template <class Base>
void* JSCallbackObject<Base>::getPrivate()
{
- return m_privateData;
+ return m_callbackObjectData->privateData;
}
template <class Base>
bool JSCallbackObject<Base>::inherits(JSClassRef c) const
{
- for (JSClassRef jsClass = m_class; jsClass; jsClass = jsClass->parentClass)
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
if (jsClass == c)
return true;
@@ -419,7 +430,7 @@ bool JSCallbackObject<Base>::inherits(JSClassRef c) const
}
template <class Base>
-JSValue* JSCallbackObject<Base>::cachedValueGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot)
+JSValue* JSCallbackObject<Base>::cachedValueGetter(ExecState*, const Identifier&, const PropertySlot& slot)
{
JSValue* v = slot.slotBase();
ASSERT(v);
@@ -427,20 +438,21 @@ JSValue* JSCallbackObject<Base>::cachedValueGetter(ExecState*, JSObject*, const
}
template <class Base>
-JSValue* JSCallbackObject<Base>::staticValueGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
+JSValue* JSCallbackObject<Base>::staticValueGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
{
- ASSERT(slot.slotBase()->inherits(&JSCallbackObject::info));
- JSCallbackObject* thisObj = static_cast<JSCallbackObject*>(slot.slotBase());
+ JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());
JSObjectRef thisRef = toRef(thisObj);
- JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
+ RefPtr<OpaqueJSString> propertyNameRef;
- for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass)
- if (OpaqueJSClass::StaticValuesTable* staticValues = jsClass->staticValues)
+ for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec))
if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
if (JSObjectGetPropertyCallback getProperty = entry->getProperty) {
- JSLock::DropAllLocks dropAllLocks;
- if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
return toJS(value);
}
@@ -448,21 +460,20 @@ JSValue* JSCallbackObject<Base>::staticValueGetter(ExecState* exec, JSObject*, c
}
template <class Base>
-JSValue* JSCallbackObject<Base>::staticFunctionGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
+JSValue* JSCallbackObject<Base>::staticFunctionGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
{
- ASSERT(slot.slotBase()->inherits(&JSCallbackObject::info));
- JSCallbackObject* thisObj = static_cast<JSCallbackObject*>(slot.slotBase());
+ JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());
// Check for cached or override property.
- PropertySlot slot2;
+ PropertySlot slot2(thisObj);
if (thisObj->Base::getOwnPropertySlot(exec, propertyName, slot2))
- return slot2.getValue(exec, thisObj, propertyName);
+ return slot2.getValue(exec, propertyName);
- for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass) {
- if (OpaqueJSClass::StaticFunctionsTable* staticFunctions = jsClass->staticFunctions) {
+ for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
- JSObject* o = new JSCallbackFunction(exec, callAsFunction, propertyName);
+ JSObject* o = new (exec) JSCallbackFunction(exec, callAsFunction, propertyName);
thisObj->putDirect(propertyName, o, entry->attributes);
return o;
}
@@ -474,22 +485,23 @@ JSValue* JSCallbackObject<Base>::staticFunctionGetter(ExecState* exec, JSObject*
}
template <class Base>
-JSValue* JSCallbackObject<Base>::callbackGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
+JSValue* JSCallbackObject<Base>::callbackGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
{
- ASSERT(slot.slotBase()->inherits(&JSCallbackObject::info));
- JSCallbackObject* thisObj = static_cast<JSCallbackObject*>(slot.slotBase());
+ JSCallbackObject* thisObj = asCallbackObject(slot.slotBase());
JSObjectRef thisRef = toRef(thisObj);
- JSStringRef propertyNameRef = toRef(propertyName.ustring().rep());
+ RefPtr<OpaqueJSString> propertyNameRef;
- for (JSClassRef jsClass = thisObj->m_class; jsClass; jsClass = jsClass->parentClass)
+ for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
- JSLock::DropAllLocks dropAllLocks;
- if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef, toRef(exec->exceptionSlot())))
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSLock::DropAllLocks dropAllLocks(exec);
+ if (JSValueRef value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), toRef(exec->exceptionSlot())))
return toJS(value);
}
return throwError(exec, ReferenceError, "hasProperty callback returned true for a property that doesn't exist.");
}
-} // namespace KJS
+} // namespace JSC
diff --git a/JavaScriptCore/API/JSClassRef.cpp b/JavaScriptCore/API/JSClassRef.cpp
index 98aaaf5..88fd70d 100644
--- a/JavaScriptCore/API/JSClassRef.cpp
+++ b/JavaScriptCore/API/JSClassRef.cpp
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
@@ -30,21 +29,18 @@
#include "APICast.h"
#include "JSCallbackObject.h"
#include "JSObjectRef.h"
-#include <kjs/JSGlobalObject.h>
+#include <runtime/InitializeThreading.h>
+#include <runtime/JSGlobalObject.h>
+#include <runtime/ObjectPrototype.h>
#include <kjs/identifier.h>
-#include <kjs/object_object.h>
-using namespace KJS;
+using namespace JSC;
const JSClassDefinition kJSClassDefinitionEmpty = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* protoClass)
- // FIXME: <rdar://problem/4949018>
- : className(definition->className)
- , parentClass(definition->parentClass)
+ : parentClass(definition->parentClass)
, prototypeClass(0)
- , staticValues(0)
- , staticFunctions(0)
, initialize(definition->initialize)
, finalize(definition->finalize)
, hasProperty(definition->hasProperty)
@@ -56,23 +52,25 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass*
, callAsConstructor(definition->callAsConstructor)
, hasInstance(definition->hasInstance)
, convertToType(definition->convertToType)
- , cachedPrototype(0)
+ , m_className(UString::Rep::createFromUTF8(definition->className))
+ , m_staticValues(0)
+ , m_staticFunctions(0)
{
+ initializeThreading();
+
if (const JSStaticValue* staticValue = definition->staticValues) {
- staticValues = new StaticValuesTable();
+ m_staticValues = new OpaqueJSClassStaticValuesTable();
while (staticValue->name) {
- // FIXME: <rdar://problem/4949018>
- staticValues->add(Identifier(staticValue->name).ustring().rep(),
+ m_staticValues->add(UString::Rep::createFromUTF8(staticValue->name),
new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes));
++staticValue;
}
}
-
+
if (const JSStaticFunction* staticFunction = definition->staticFunctions) {
- staticFunctions = new StaticFunctionsTable();
+ m_staticFunctions = new OpaqueJSClassStaticFunctionsTable();
while (staticFunction->name) {
- // FIXME: <rdar://problem/4949018>
- staticFunctions->add(Identifier(staticFunction->name).ustring().rep(),
+ m_staticFunctions->add(UString::Rep::createFromUTF8(staticFunction->name),
new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes));
++staticFunction;
}
@@ -84,48 +82,131 @@ OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass*
OpaqueJSClass::~OpaqueJSClass()
{
- if (staticValues) {
- deleteAllValues(*staticValues);
- delete staticValues;
+ ASSERT(!m_className.rep()->identifierTable());
+
+ if (m_staticValues) {
+ OpaqueJSClassStaticValuesTable::const_iterator end = m_staticValues->end();
+ for (OpaqueJSClassStaticValuesTable::const_iterator it = m_staticValues->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ delete it->second;
+ }
+ delete m_staticValues;
}
- if (staticFunctions) {
- deleteAllValues(*staticFunctions);
- delete staticFunctions;
+ if (m_staticFunctions) {
+ OpaqueJSClassStaticFunctionsTable::const_iterator end = m_staticFunctions->end();
+ for (OpaqueJSClassStaticFunctionsTable::const_iterator it = m_staticFunctions->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ delete it->second;
+ }
+ delete m_staticFunctions;
}
if (prototypeClass)
JSClassRelease(prototypeClass);
}
-JSClassRef OpaqueJSClass::createNoAutomaticPrototype(const JSClassDefinition* definition)
+PassRefPtr<OpaqueJSClass> OpaqueJSClass::createNoAutomaticPrototype(const JSClassDefinition* definition)
{
- return new OpaqueJSClass(definition, 0);
+ return adoptRef(new OpaqueJSClass(definition, 0));
}
void clearReferenceToPrototype(JSObjectRef prototype)
{
- OpaqueJSClass* jsClass = static_cast<OpaqueJSClass*>(JSObjectGetPrivate(prototype));
- ASSERT(jsClass);
- jsClass->cachedPrototype = 0;
+ OpaqueJSClassContextData* jsClassData = static_cast<OpaqueJSClassContextData*>(JSObjectGetPrivate(prototype));
+ ASSERT(jsClassData);
+ jsClassData->cachedPrototype = 0;
}
-JSClassRef OpaqueJSClass::create(const JSClassDefinition* definition)
+PassRefPtr<OpaqueJSClass> OpaqueJSClass::create(const JSClassDefinition* definition)
{
if (const JSStaticFunction* staticFunctions = definition->staticFunctions) {
// copy functions into a prototype class
JSClassDefinition protoDefinition = kJSClassDefinitionEmpty;
protoDefinition.staticFunctions = staticFunctions;
protoDefinition.finalize = clearReferenceToPrototype;
- OpaqueJSClass* protoClass = new OpaqueJSClass(&protoDefinition, 0);
+
+ // We are supposed to use JSClassRetain/Release but since we know that we currently have
+ // the only reference to this class object we cheat and use a RefPtr instead.
+ RefPtr<OpaqueJSClass> protoClass = adoptRef(new OpaqueJSClass(&protoDefinition, 0));
// remove functions from the original class
JSClassDefinition objectDefinition = *definition;
objectDefinition.staticFunctions = 0;
- return new OpaqueJSClass(&objectDefinition, protoClass);
+
+ return adoptRef(new OpaqueJSClass(&objectDefinition, protoClass.get()));
+ }
+
+ return adoptRef(new OpaqueJSClass(definition, 0));
+}
+
+OpaqueJSClassContextData::OpaqueJSClassContextData(OpaqueJSClass* jsClass)
+ : m_class(jsClass)
+ , cachedPrototype(0)
+{
+ if (jsClass->m_staticValues) {
+ staticValues = new OpaqueJSClassStaticValuesTable;
+ OpaqueJSClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end();
+ for (OpaqueJSClassStaticValuesTable::const_iterator it = jsClass->m_staticValues->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ staticValues->add(UString::Rep::createCopying(it->first->data(), it->first->size()),
+ new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes));
+ }
+
+ } else
+ staticValues = 0;
+
+
+ if (jsClass->m_staticFunctions) {
+ staticFunctions = new OpaqueJSClassStaticFunctionsTable;
+ OpaqueJSClassStaticFunctionsTable::const_iterator end = jsClass->m_staticFunctions->end();
+ for (OpaqueJSClassStaticFunctionsTable::const_iterator it = jsClass->m_staticFunctions->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ staticFunctions->add(UString::Rep::createCopying(it->first->data(), it->first->size()),
+ new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes));
+ }
+
+ } else
+ staticFunctions = 0;
+}
+
+OpaqueJSClassContextData::~OpaqueJSClassContextData()
+{
+ if (staticValues) {
+ deleteAllValues(*staticValues);
+ delete staticValues;
}
- return new OpaqueJSClass(definition, 0);
+ if (staticFunctions) {
+ deleteAllValues(*staticFunctions);
+ delete staticFunctions;
+ }
+}
+
+OpaqueJSClassContextData& OpaqueJSClass::contextData(ExecState* exec)
+{
+ OpaqueJSClassContextData*& contextData = exec->globalData().opaqueJSClassData.add(this, 0).first->second;
+ if (!contextData)
+ contextData = new OpaqueJSClassContextData(this);
+ return *contextData;
+}
+
+UString OpaqueJSClass::className()
+{
+ // Make a deep copy, so that the caller has no chance to put the original into IdentifierTable.
+ return UString(m_className.data(), m_className.size());
+}
+
+OpaqueJSClassStaticValuesTable* OpaqueJSClass::staticValues(JSC::ExecState* exec)
+{
+ OpaqueJSClassContextData& jsClassData = contextData(exec);
+ return jsClassData.staticValues;
+}
+
+OpaqueJSClassStaticFunctionsTable* OpaqueJSClass::staticFunctions(JSC::ExecState* exec)
+{
+ OpaqueJSClassContextData& jsClassData = contextData(exec);
+ return jsClassData.staticFunctions;
}
/*!
@@ -136,7 +217,7 @@ JSClassRef OpaqueJSClass::create(const JSClassDefinition* definition)
@param jsClass A JSClass whose prototype you want to get.
@result The JSObject prototype that was automatically generated for jsClass, or NULL if no prototype was automatically generated. This is the prototype that will be used when constructing an object using jsClass.
*/
-JSObject* OpaqueJSClass::prototype(JSContextRef ctx)
+JSObject* OpaqueJSClass::prototype(ExecState* exec)
{
/* Class (C++) and prototype (JS) inheritance are parallel, so:
* (C++) | (JS)
@@ -148,17 +229,16 @@ JSObject* OpaqueJSClass::prototype(JSContextRef ctx)
if (!prototypeClass)
return 0;
-
- ExecState* exec = toJS(ctx);
-
- if (!cachedPrototype) {
+
+ OpaqueJSClassContextData& jsClassData = contextData(exec);
+
+ if (!jsClassData.cachedPrototype) {
// Recursive, but should be good enough for our purposes
- JSObject* parentPrototype = 0;
- if (parentClass)
- parentPrototype = parentClass->prototype(ctx); // can be null
- if (!parentPrototype)
- parentPrototype = exec->dynamicGlobalObject()->objectPrototype();
- cachedPrototype = new JSCallbackObject<JSObject>(exec, prototypeClass, parentPrototype, this); // set ourself as the object's private data, so it can clear our reference on destruction
+ jsClassData.cachedPrototype = new (exec) JSCallbackObject<JSObject>(exec, exec->lexicalGlobalObject()->callbackObjectStructure(), prototypeClass, &jsClassData); // set jsClassData as the object's private data, so it can clear our reference on destruction
+ if (parentClass) {
+ if (JSObject* prototype = parentClass->prototype(exec))
+ jsClassData.cachedPrototype->setPrototype(prototype);
+ }
}
- return cachedPrototype;
+ return jsClassData.cachedPrototype;
}
diff --git a/JavaScriptCore/API/JSClassRef.h b/JavaScriptCore/API/JSClassRef.h
index eb2b35b..71fae18 100644
--- a/JavaScriptCore/API/JSClassRef.h
+++ b/JavaScriptCore/API/JSClassRef.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -29,7 +28,7 @@
#include "JSObjectRef.h"
-#include <kjs/object.h>
+#include <runtime/JSObject.h>
#include <kjs/protect.h>
#include <kjs/ustring.h>
#include <wtf/HashMap.h>
@@ -56,22 +55,42 @@ struct StaticFunctionEntry {
JSPropertyAttributes attributes;
};
-struct OpaqueJSClass : public RefCounted<OpaqueJSClass> {
- static OpaqueJSClass* create(const JSClassDefinition*);
- static OpaqueJSClass* createNoAutomaticPrototype(const JSClassDefinition*);
+typedef HashMap<RefPtr<JSC::UString::Rep>, StaticValueEntry*> OpaqueJSClassStaticValuesTable;
+typedef HashMap<RefPtr<JSC::UString::Rep>, StaticFunctionEntry*> OpaqueJSClassStaticFunctionsTable;
+
+class OpaqueJSClass;
+
+// An OpaqueJSClass (JSClass) is created without a context, so it can be used with any context, even across context groups.
+// This structure holds data members that vary across context groups.
+struct OpaqueJSClassContextData : Noncopyable {
+ OpaqueJSClassContextData(OpaqueJSClass*);
+ ~OpaqueJSClassContextData();
+
+ // It is necessary to keep OpaqueJSClass alive because of the following rare scenario:
+ // 1. A class is created and used, so its context data is stored in JSGlobalData hash map.
+ // 2. The class is released, and when all JS objects that use it are collected, OpaqueJSClass
+ // is deleted (that's the part prevented by this RefPtr).
+ // 3. Another class is created at the same address.
+ // 4. When it is used, the old context data is found in JSGlobalData and used.
+ RefPtr<OpaqueJSClass> m_class;
+
+ OpaqueJSClassStaticValuesTable* staticValues;
+ OpaqueJSClassStaticFunctionsTable* staticFunctions;
+ JSC::JSObject* cachedPrototype;
+};
+
+struct OpaqueJSClass : public ThreadSafeShared<OpaqueJSClass> {
+ static PassRefPtr<OpaqueJSClass> create(const JSClassDefinition*);
+ static PassRefPtr<OpaqueJSClass> createNoAutomaticPrototype(const JSClassDefinition*);
~OpaqueJSClass();
- KJS::JSObject* prototype(JSContextRef ctx);
-
- typedef HashMap<RefPtr<KJS::UString::Rep>, StaticValueEntry*> StaticValuesTable;
- typedef HashMap<RefPtr<KJS::UString::Rep>, StaticFunctionEntry*> StaticFunctionsTable;
+ JSC::UString className();
+ OpaqueJSClassStaticValuesTable* staticValues(JSC::ExecState*);
+ OpaqueJSClassStaticFunctionsTable* staticFunctions(JSC::ExecState*);
+ JSC::JSObject* prototype(JSC::ExecState*);
- KJS::UString className;
OpaqueJSClass* parentClass;
OpaqueJSClass* prototypeClass;
-
- StaticValuesTable* staticValues;
- StaticFunctionsTable* staticFunctions;
JSObjectInitializeCallback initialize;
JSObjectFinalizeCallback finalize;
@@ -86,12 +105,18 @@ struct OpaqueJSClass : public RefCounted<OpaqueJSClass> {
JSObjectConvertToTypeCallback convertToType;
private:
+ friend struct OpaqueJSClassContextData;
+
OpaqueJSClass();
OpaqueJSClass(const OpaqueJSClass&);
OpaqueJSClass(const JSClassDefinition*, OpaqueJSClass* protoClass);
-
- friend void clearReferenceToPrototype(JSObjectRef prototype);
- KJS::JSObject* cachedPrototype;
+
+ OpaqueJSClassContextData& contextData(JSC::ExecState*);
+
+ // UStrings in these data members should not be put into any IdentifierTable.
+ JSC::UString m_className;
+ OpaqueJSClassStaticValuesTable* m_staticValues;
+ OpaqueJSClassStaticFunctionsTable* m_staticFunctions;
};
#endif // JSClassRef_h
diff --git a/JavaScriptCore/API/JSContextRef.cpp b/JavaScriptCore/API/JSContextRef.cpp
index 203326e..ee7286d 100644
--- a/JavaScriptCore/API/JSContextRef.cpp
+++ b/JavaScriptCore/API/JSContextRef.cpp
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
@@ -28,49 +27,104 @@
#include "JSContextRef.h"
#include "APICast.h"
+#include "InitializeThreading.h"
#include "JSCallbackObject.h"
#include "JSClassRef.h"
#include "JSGlobalObject.h"
-#include "object.h"
+#include "JSObject.h"
#include <wtf/Platform.h>
-using namespace KJS;
+using namespace JSC;
+
+JSContextGroupRef JSContextGroupCreate()
+{
+ return toRef(JSGlobalData::create().releaseRef());
+}
+
+JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group)
+{
+ toJS(group)->ref();
+ return group;
+}
+
+void JSContextGroupRelease(JSContextGroupRef group)
+{
+ toJS(group)->deref();
+}
JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass)
{
- JSLock lock;
+ JSLock lock(true);
+ return JSGlobalContextCreateInGroup(toRef(&JSGlobalData::sharedInstance()), globalObjectClass);
+}
+
+JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass)
+{
+ initializeThreading();
+
+ JSLock lock(true);
+
+ RefPtr<JSGlobalData> globalData = group ? PassRefPtr<JSGlobalData>(toJS(group)) : JSGlobalData::create();
if (!globalObjectClass) {
- JSGlobalObject* globalObject = new JSGlobalObject;
+ JSGlobalObject* globalObject = new (globalData.get()) JSGlobalObject;
return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec()));
}
- JSGlobalObject* globalObject = new JSCallbackObject<JSGlobalObject>(globalObjectClass);
- JSGlobalContextRef ctx = toGlobalRef(globalObject->globalExec());
- JSValue* prototype = globalObjectClass->prototype(ctx);
+ JSGlobalObject* globalObject = new (globalData.get()) JSCallbackObject<JSGlobalObject>(globalObjectClass);
+ ExecState* exec = globalObject->globalExec();
+ JSValue* prototype = globalObjectClass->prototype(exec);
if (!prototype)
prototype = jsNull();
- globalObject->reset(prototype);
- return JSGlobalContextRetain(ctx);
+ globalObject->resetPrototype(prototype);
+ return JSGlobalContextRetain(toGlobalRef(exec));
}
JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ JSLock lock(exec);
+
+ JSGlobalData& globalData = exec->globalData();
+
+ globalData.heap.registerThread();
+
gcProtect(exec->dynamicGlobalObject());
+ globalData.ref();
return ctx;
}
void JSGlobalContextRelease(JSGlobalContextRef ctx)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ JSLock lock(exec);
+
gcUnprotect(exec->dynamicGlobalObject());
+
+ JSGlobalData& globalData = exec->globalData();
+ if (globalData.refCount() == 2) { // One reference is held by JSGlobalObject, another added by JSGlobalContextRetain().
+ // The last reference was released, this is our last chance to collect.
+ ASSERT(!globalData.heap.protectedObjectCount());
+ ASSERT(!globalData.heap.isBusy());
+ globalData.heap.destroy();
+ } else
+ globalData.heap.collect();
+
+ globalData.deref();
}
JSObjectRef JSContextGetGlobalObject(JSContextRef ctx)
{
ExecState* exec = toJS(ctx);
- return toRef(exec->dynamicGlobalObject());
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ // It is necessary to call toThisObject to get the wrapper object when used with WebCore.
+ return toRef(exec->lexicalGlobalObject()->toThisObject(exec));
+}
+
+JSContextGroupRef JSContextGetGroup(JSContextRef ctx)
+{
+ ExecState* exec = toJS(ctx);
+ return toRef(&exec->globalData());
}
diff --git a/JavaScriptCore/API/JSContextRef.h b/JavaScriptCore/API/JSContextRef.h
index df0a397..bb6ea6e 100644
--- a/JavaScriptCore/API/JSContextRef.h
+++ b/JavaScriptCore/API/JSContextRef.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -29,8 +28,11 @@
#include <JavaScriptCore/JSObjectRef.h>
#include <JavaScriptCore/JSValueRef.h>
+#include <JavaScriptCore/WebKitAvailability.h>
+#ifndef __cplusplus
#include <stdbool.h>
+#endif
#ifdef __cplusplus
extern "C" {
@@ -38,14 +40,58 @@ extern "C" {
/*!
@function
+@abstract Creates a JavaScript context group.
+@discussion A JSContextGroup associates JavaScript contexts with one another.
+ Contexts in the same group may share and exchange JavaScript objects. Sharing and/or exchanging
+ JavaScript objects between contexts in different groups will produce undefined behavior.
+ When objects from the same context group are used in multiple threads, explicit
+ synchronization is required.
+@result The created JSContextGroup.
+*/
+JS_EXPORT JSContextGroupRef JSContextGroupCreate() AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
+
+/*!
+@function
+@abstract Retains a JavaScript context group.
+@param group The JSContextGroup to retain.
+@result A JSContextGroup that is the same as group.
+*/
+JS_EXPORT JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group) AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
+
+/*!
+@function
+@abstract Releases a JavaScript context group.
+@param group The JSContextGroup to release.
+*/
+JS_EXPORT void JSContextGroupRelease(JSContextGroupRef group) AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
+
+/*!
+@function
@abstract Creates a global JavaScript execution context.
@discussion JSGlobalContextCreate allocates a global object and populates it with all the
built-in JavaScript objects, such as Object, Function, String, and Array.
+
+ The created context can only be used on the main thread. JavaScript values cannot be
+ shared or exchanged between contexts.
@param globalObjectClass The class to use when creating the global object. Pass
NULL to use the default object class.
@result A JSGlobalContext with a global object of class globalObjectClass.
*/
-JS_EXPORT JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass);
+JS_EXPORT JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass) AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1;
+
+/*!
+@function
+@abstract Creates a global JavaScript execution context in the context group provided.
+@discussion JSGlobalContextCreateInGroup allocates a global object and populates it with
+ all the built-in JavaScript objects, such as Object, Function, String, and Array.
+@param globalObjectClass The class to use when creating the global object. Pass
+ NULL to use the default object class.
+@param group The context group to use. The created global context retains the group.
+ Pass NULL to create a unique group for the context.
+@result A JSGlobalContext with a global object of class globalObjectClass and a context
+ group equal to group.
+*/
+JS_EXPORT JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass) AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
/*!
@function
@@ -70,8 +116,16 @@ JS_EXPORT void JSGlobalContextRelease(JSGlobalContextRef ctx);
*/
JS_EXPORT JSObjectRef JSContextGetGlobalObject(JSContextRef ctx);
+/*!
+@function
+@abstract Gets the context group to which a JavaScript execution context belongs.
+@param ctx The JSContext whose group you want to get.
+@result ctx's group.
+*/
+JS_EXPORT JSContextGroupRef JSContextGetGroup(JSContextRef ctx) AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
+
#ifdef __cplusplus
}
#endif
-#endif // JSContextRef_h
+#endif /* JSContextRef_h */
diff --git a/JavaScriptCore/API/JSObjectRef.cpp b/JavaScriptCore/API/JSObjectRef.cpp
index c6cda25..a4f32ba 100644
--- a/JavaScriptCore/API/JSObjectRef.cpp
+++ b/JavaScriptCore/API/JSObjectRef.cpp
@@ -1,6 +1,6 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Kelvin W Sherlock (ksherlock@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,108 +27,200 @@
#include "config.h"
#include "JSObjectRef.h"
-#include <wtf/Platform.h>
#include "APICast.h"
-#include "JSValueRef.h"
+#include "DateConstructor.h"
+#include "ErrorConstructor.h"
+#include "FunctionConstructor.h"
+#include "JSArray.h"
#include "JSCallbackConstructor.h"
#include "JSCallbackFunction.h"
#include "JSCallbackObject.h"
#include "JSClassRef.h"
+#include "JSFunction.h"
#include "JSGlobalObject.h"
-
+#include "JSObject.h"
+#include "JSRetainPtr.h"
+#include "JSString.h"
+#include "JSValueRef.h"
+#include "ObjectPrototype.h"
#include "PropertyNameArray.h"
-#include "function.h"
-#include "function_object.h"
+#include "RegExpConstructor.h"
#include "identifier.h"
-#include "internal.h"
-#include "object.h"
-#include "object_object.h"
+#include <wtf/Platform.h>
-using namespace KJS;
+using namespace JSC;
JSClassRef JSClassCreate(const JSClassDefinition* definition)
{
- JSLock lock;
- JSClassRef jsClass = (definition->attributes & kJSClassAttributeNoAutomaticPrototype)
+ RefPtr<OpaqueJSClass> jsClass = (definition->attributes & kJSClassAttributeNoAutomaticPrototype)
? OpaqueJSClass::createNoAutomaticPrototype(definition)
: OpaqueJSClass::create(definition);
- return JSClassRetain(jsClass);
+ return jsClass.release().releaseRef();
}
JSClassRef JSClassRetain(JSClassRef jsClass)
{
- JSLock lock;
jsClass->ref();
return jsClass;
}
void JSClassRelease(JSClassRef jsClass)
{
- JSLock lock;
jsClass->deref();
}
JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
if (!jsClass)
- return toRef(new JSObject(exec->lexicalGlobalObject()->objectPrototype())); // slightly more efficient
+ return toRef(new (exec) JSObject(exec->lexicalGlobalObject()->emptyObjectStructure())); // slightly more efficient
- JSValue* jsPrototype = jsClass->prototype(ctx);
- if (!jsPrototype)
- jsPrototype = exec->lexicalGlobalObject()->objectPrototype();
+ JSCallbackObject<JSObject>* object = new (exec) JSCallbackObject<JSObject>(exec, exec->lexicalGlobalObject()->callbackObjectStructure(), jsClass, data);
+ if (JSObject* prototype = jsClass->prototype(exec))
+ object->setPrototype(prototype);
- return toRef(new JSCallbackObject<JSObject>(exec, jsClass, jsPrototype, data));
+ return toRef(object);
}
JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
- Identifier nameID = name ? Identifier(toJS(name)) : Identifier("anonymous");
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous");
- return toRef(new JSCallbackFunction(exec, callAsFunction, nameID));
+ return toRef(new (exec) JSCallbackFunction(exec, callAsFunction, nameID));
}
JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
-
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSValue* jsPrototype = jsClass
- ? jsClass->prototype(ctx)
- : exec->dynamicGlobalObject()->objectPrototype();
+ ? jsClass->prototype(exec)
+ : exec->lexicalGlobalObject()->objectPrototype();
- JSCallbackConstructor* constructor = new JSCallbackConstructor(exec, jsClass, callAsConstructor);
+ JSCallbackConstructor* constructor = new (exec) JSCallbackConstructor(exec->lexicalGlobalObject()->callbackConstructorStructure(), jsClass, callAsConstructor);
constructor->putDirect(exec->propertyNames().prototype, jsPrototype, DontEnum | DontDelete | ReadOnly);
return toRef(constructor);
}
JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
{
- JSLock lock;
-
ExecState* exec = toJS(ctx);
- UString::Rep* bodyRep = toJS(body);
- UString::Rep* sourceURLRep = sourceURL ? toJS(sourceURL) : &UString::Rep::null;
-
- Identifier nameID = name ? Identifier(toJS(name)) : Identifier("anonymous");
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous");
- List args;
+ ArgList args;
for (unsigned i = 0; i < parameterCount; i++)
- args.append(jsString(UString(toJS(parameterNames[i]))));
- args.append(jsString(UString(bodyRep)));
+ args.append(jsString(exec, parameterNames[i]->ustring()));
+ args.append(jsString(exec, body->ustring()));
+
+ JSObject* result = constructFunction(exec, args, nameID, sourceURL->ustring(), startingLineNumber);
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec->exception());
+ exec->clearException();
+ result = 0;
+ }
+ return toRef(result);
+}
+
+JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ JSObject* result;
+ if (argumentCount) {
+ ArgList argList;
+ for (size_t i = 0; i < argumentCount; ++i)
+ argList.append(toJS(arguments[i]));
+
+ result = constructArray(exec, argList);
+ } else
+ result = constructEmptyArray(exec);
+
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec->exception());
+ exec->clearException();
+ result = 0;
+ }
+
+ return toRef(result);
+}
+
+JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ ArgList argList;
+ for (size_t i = 0; i < argumentCount; ++i)
+ argList.append(toJS(arguments[i]));
+
+ JSObject* result = constructDate(exec, argList);
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec->exception());
+ exec->clearException();
+ result = 0;
+ }
+
+ return toRef(result);
+}
- JSObject* result = exec->dynamicGlobalObject()->functionConstructor()->construct(exec, args, nameID, UString(sourceURLRep), startingLineNumber);
+JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ ArgList argList;
+ for (size_t i = 0; i < argumentCount; ++i)
+ argList.append(toJS(arguments[i]));
+
+ JSObject* result = constructError(exec, argList);
if (exec->hadException()) {
if (exception)
*exception = toRef(exec->exception());
exec->clearException();
result = 0;
}
+
+ return toRef(result);
+}
+
+JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ ArgList argList;
+ for (size_t i = 0; i < argumentCount; ++i)
+ argList.append(toJS(arguments[i]));
+
+ JSObject* result = constructRegExp(exec, argList);
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec->exception());
+ exec->clearException();
+ result = 0;
+ }
+
return toRef(result);
}
@@ -143,27 +235,29 @@ void JSObjectSetPrototype(JSContextRef, JSObjectRef object, JSValueRef value)
JSObject* jsObject = toJS(object);
JSValue* jsValue = toJS(value);
- jsObject->setPrototype(jsValue);
+ jsObject->setPrototype(jsValue->isObject() ? jsValue : jsNull());
}
bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSObject* jsObject = toJS(object);
- UString::Rep* nameRep = toJS(propertyName);
- return jsObject->hasProperty(exec, Identifier(nameRep));
+ return jsObject->hasProperty(exec, propertyName->identifier(&exec->globalData()));
}
JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSObject* jsObject = toJS(object);
- UString::Rep* nameRep = toJS(propertyName);
- JSValue* jsValue = jsObject->get(exec, Identifier(nameRep));
+ JSValue* jsValue = jsObject->get(exec, propertyName->identifier(&exec->globalData()));
if (exec->hadException()) {
if (exception)
*exception = toRef(exec->exception());
@@ -174,13 +268,21 @@ JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef
void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSObject* jsObject = toJS(object);
- UString::Rep* nameRep = toJS(propertyName);
+ Identifier name(propertyName->identifier(&exec->globalData()));
JSValue* jsValue = toJS(value);
-
- jsObject->put(exec, Identifier(nameRep), jsValue, attributes);
+
+ if (attributes && !jsObject->hasProperty(exec, name))
+ jsObject->putWithAttributes(exec, name, jsValue, attributes);
+ else {
+ PutPropertySlot slot;
+ jsObject->put(exec, name, jsValue, slot);
+ }
+
if (exec->hadException()) {
if (exception)
*exception = toRef(exec->exception());
@@ -190,8 +292,10 @@ void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef prope
JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSObject* jsObject = toJS(object);
JSValue* jsValue = jsObject->get(exec, propertyIndex);
@@ -206,8 +310,10 @@ JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsi
void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSObject* jsObject = toJS(object);
JSValue* jsValue = toJS(value);
@@ -221,12 +327,13 @@ void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned p
bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSObject* jsObject = toJS(object);
- UString::Rep* nameRep = toJS(propertyName);
- bool result = jsObject->deleteProperty(exec, Identifier(nameRep));
+ bool result = jsObject->deleteProperty(exec, propertyName->identifier(&exec->globalData()));
if (exec->hadException()) {
if (exception)
*exception = toRef(exec->exception());
@@ -264,25 +371,32 @@ bool JSObjectSetPrivate(JSObjectRef object, void* data)
bool JSObjectIsFunction(JSContextRef, JSObjectRef object)
{
- JSObject* jsObject = toJS(object);
- return jsObject->implementsCall();
+ CallData callData;
+ return toJS(object)->getCallData(callData) != CallTypeNone;
}
JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSObject* jsObject = toJS(object);
JSObject* jsThisObject = toJS(thisObject);
if (!jsThisObject)
- jsThisObject = exec->dynamicGlobalObject();
-
- List argList;
+ jsThisObject = exec->globalThisValue();
+
+ ArgList argList;
for (size_t i = 0; i < argumentCount; i++)
argList.append(toJS(arguments[i]));
- JSValueRef result = toRef(jsObject->call(exec, jsThisObject, argList)); // returns NULL if object->implementsCall() is false
+ CallData callData;
+ CallType callType = jsObject->getCallData(callData);
+ if (callType == CallTypeNone)
+ return 0;
+
+ JSValueRef result = toRef(call(exec, jsObject, callType, callData, jsThisObject, argList));
if (exec->hadException()) {
if (exception)
*exception = toRef(exec->exception());
@@ -295,20 +409,27 @@ JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObject
bool JSObjectIsConstructor(JSContextRef, JSObjectRef object)
{
JSObject* jsObject = toJS(object);
- return jsObject->implementsConstruct();
+ ConstructData constructData;
+ return jsObject->getConstructData(constructData) != ConstructTypeNone;
}
JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSObject* jsObject = toJS(object);
-
- List argList;
+
+ ConstructData constructData;
+ ConstructType constructType = jsObject->getConstructData(constructData);
+ if (constructType == ConstructTypeNone)
+ return 0;
+
+ ArgList argList;
for (size_t i = 0; i < argumentCount; i++)
argList.append(toJS(arguments[i]));
-
- JSObjectRef result = toRef(jsObject->construct(exec, argList)); // returns NULL if object->implementsCall() is false
+ JSObjectRef result = toRef(construct(exec, jsObject, constructType, constructData, argList));
if (exec->hadException()) {
if (exception)
*exception = toRef(exec->exception());
@@ -318,40 +439,51 @@ JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size
return result;
}
-struct OpaqueJSPropertyNameArray
-{
- OpaqueJSPropertyNameArray() : refCount(0)
+struct OpaqueJSPropertyNameArray {
+ OpaqueJSPropertyNameArray(JSGlobalData* globalData)
+ : refCount(0)
+ , globalData(globalData)
{
}
unsigned refCount;
- PropertyNameArray array;
+ JSGlobalData* globalData;
+ Vector<JSRetainPtr<JSStringRef> > array;
};
JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef object)
{
- JSLock lock;
JSObject* jsObject = toJS(object);
ExecState* exec = toJS(ctx);
-
- JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray();
- jsObject->getPropertyNames(exec, propertyNames->array);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ JSGlobalData* globalData = &exec->globalData();
+
+ JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(globalData);
+ PropertyNameArray array(globalData);
+ jsObject->getPropertyNames(exec, array);
+
+ size_t size = array.size();
+ propertyNames->array.reserveCapacity(size);
+ for (size_t i = 0; i < size; ++i)
+ propertyNames->array.append(JSRetainPtr<JSStringRef>(Adopt, OpaqueJSString::create(array[i].ustring()).releaseRef()));
return JSPropertyNameArrayRetain(propertyNames);
}
JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array)
{
- JSLock lock;
++array->refCount;
return array;
}
void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array)
{
- JSLock lock;
- if (--array->refCount == 0)
+ if (--array->refCount == 0) {
+ JSLock lock(array->globalData->isSharedInstance);
delete array;
+ }
}
size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array)
@@ -361,14 +493,15 @@ size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array)
JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index)
{
- return toRef(array->array[static_cast<unsigned>(index)].ustring().rep());
+ return array->array[static_cast<unsigned>(index)].get();
}
void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef array, JSStringRef propertyName)
{
- JSLock lock;
PropertyNameArray* propertyNames = toJS(array);
- UString::Rep* rep = toJS(propertyName);
-
- propertyNames->add(Identifier(rep));
+
+ propertyNames->globalData()->heap.registerThread();
+ JSLock lock(propertyNames->globalData()->isSharedInstance);
+
+ propertyNames->add(propertyName->identifier(propertyNames->globalData()));
}
diff --git a/JavaScriptCore/API/JSObjectRef.h b/JavaScriptCore/API/JSObjectRef.h
index bf4041f..461764c 100644
--- a/JavaScriptCore/API/JSObjectRef.h
+++ b/JavaScriptCore/API/JSObjectRef.h
@@ -1,6 +1,6 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Kelvin W Sherlock (ksherlock@gmail.com)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -29,9 +29,12 @@
#include <JavaScriptCore/JSBase.h>
#include <JavaScriptCore/JSValueRef.h>
+#include <JavaScriptCore/WebKitAvailability.h>
+#ifndef __cplusplus
#include <stdbool.h>
-#include <stddef.h> // for size_t
+#endif
+#include <stddef.h> /* for size_t */
#ifdef __cplusplus
extern "C" {
@@ -338,7 +341,7 @@ Standard JavaScript practice calls for storing function objects in prototypes, s
A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
*/
typedef struct {
- int version; // current (and only) version is 0
+ int version; /* current (and only) version is 0 */
JSClassAttributes attributes;
const char* className;
@@ -428,6 +431,52 @@ JS_EXPORT JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStrin
JS_EXPORT JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor);
/*!
+ @function
+ @abstract Creates a JavaScript Array object.
+ @param ctx The execution context to use.
+ @param argumentCount An integer count of the number of arguments in arguments.
+ @param arguments A JSValue array of data to populate the Array with. Pass NULL if argumentCount is 0.
+ @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
+ @result A JSObject that is an Array.
+ @discussion The behavior of this function does not exactly match the behavior of the built-in Array constructor. Specifically, if one argument
+ is supplied, this function returns an array with one element.
+ */
+JS_EXPORT JSObjectRef JSObjectMakeArray(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
+
+/*!
+ @function
+ @abstract Creates a JavaScript Date object, as if by invoking the built-in Date constructor.
+ @param ctx The execution context to use.
+ @param argumentCount An integer count of the number of arguments in arguments.
+ @param arguments A JSValue array of arguments to pass to the Date Constructor. Pass NULL if argumentCount is 0.
+ @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
+ @result A JSObject that is a Date.
+ */
+JS_EXPORT JSObjectRef JSObjectMakeDate(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
+
+/*!
+ @function
+ @abstract Creates a JavaScript Error object, as if by invoking the built-in Error constructor.
+ @param ctx The execution context to use.
+ @param argumentCount An integer count of the number of arguments in arguments.
+ @param arguments A JSValue array of arguments to pass to the Error Constructor. Pass NULL if argumentCount is 0.
+ @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
+ @result A JSObject that is a Error.
+ */
+JS_EXPORT JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
+
+/*!
+ @function
+ @abstract Creates a JavaScript RegExp object, as if by invoking the built-in RegExp constructor.
+ @param ctx The execution context to use.
+ @param argumentCount An integer count of the number of arguments in arguments.
+ @param arguments A JSValue array of arguments to pass to the RegExp Constructor. Pass NULL if argumentCount is 0.
+ @param exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
+ @result A JSObject that is a RegExp.
+ */
+JS_EXPORT JSObjectRef JSObjectMakeRegExp(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) AVAILABLE_AFTER_WEBKIT_VERSION_3_1;
+
+/*!
@function
@abstract Creates a function with a given script as its body.
@param ctx The execution context to use.
@@ -642,4 +691,4 @@ JS_EXPORT void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef acc
}
#endif
-#endif // JSObjectRef_h
+#endif /* JSObjectRef_h */
diff --git a/JavaScriptCore/API/JSProfilerPrivate.cpp b/JavaScriptCore/API/JSProfilerPrivate.cpp
new file mode 100644
index 0000000..ea277f0
--- /dev/null
+++ b/JavaScriptCore/API/JSProfilerPrivate.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSProfilerPrivate.h"
+
+#include "APICast.h"
+#include "OpaqueJSString.h"
+#include "Profiler.h"
+
+using namespace JSC;
+
+void JSStartProfiling(JSContextRef ctx, JSStringRef title)
+{
+ Profiler::profiler()->startProfiling(toJS(ctx), title->ustring());
+}
+
+void JSEndProfiling(JSContextRef ctx, JSStringRef title)
+{
+ ExecState* exec = toJS(ctx);
+ Profiler* profiler = Profiler::profiler();
+ profiler->stopProfiling(exec, title->ustring());
+}
+
diff --git a/JavaScriptCore/API/JSProfilerPrivate.h b/JavaScriptCore/API/JSProfilerPrivate.h
new file mode 100644
index 0000000..b3fe533
--- /dev/null
+++ b/JavaScriptCore/API/JSProfilerPrivate.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JSProfiler_h
+#define JSProfiler_h
+
+#include <JavaScriptCore/JSBase.h>
+
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*!
+@function JSStartProfiling
+@abstract Enables the profler.
+@param ctx The execution context to use.
+@param title The title of the profile.
+@result The profiler is turned on.
+*/
+JS_EXPORT void JSStartProfiling(JSContextRef ctx, JSStringRef title);
+
+/*!
+@function JSEndProfiling
+@abstract Disables the profler.
+@param ctx The execution context to use.
+@param title The title of the profile.
+@result The profiler is turned off. If there is no name, the most recently started
+ profile is stopped. If the name does not match any profile then no profile
+ is stopped.
+*/
+JS_EXPORT void JSEndProfiling(JSContextRef ctx, JSStringRef title);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSProfiler_h */
diff --git a/JavaScriptCore/API/JSStringRef.cpp b/JavaScriptCore/API/JSStringRef.cpp
index 9a307d0..6452ffc 100644
--- a/JavaScriptCore/API/JSStringRef.cpp
+++ b/JavaScriptCore/API/JSStringRef.cpp
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
@@ -27,92 +26,77 @@
#include "config.h"
#include "JSStringRef.h"
-#include <wtf/Platform.h>
-
-#include "APICast.h"
-#include <kjs/JSLock.h>
-#include <kjs/JSType.h>
-#include <kjs/internal.h>
-#include <kjs/operations.h>
-#include <kjs/ustring.h>
-#include <kjs/value.h>
+#include "OpaqueJSString.h"
#include <wtf/unicode/UTF8.h>
-using namespace KJS;
+using namespace JSC;
using namespace WTF::Unicode;
JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars)
{
- JSLock lock;
- return toRef(UString(reinterpret_cast<const KJS::UChar*>(chars), static_cast<int>(numChars)).rep()->ref());
+ return OpaqueJSString::create(chars, numChars).releaseRef();
}
JSStringRef JSStringCreateWithUTF8CString(const char* string)
{
- JSLock lock;
-
- size_t length = strlen(string);
- Vector< ::UChar, 1024> buffer(length);
- ::UChar* p = buffer.data();
- if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length))
- return 0;
-
- return toRef(UString(reinterpret_cast<KJS::UChar*>(buffer.data()), p - buffer.data()).rep()->ref());
+ if (string) {
+ size_t length = strlen(string);
+ Vector<UChar, 1024> buffer(length);
+ UChar* p = buffer.data();
+ if (conversionOK == convertUTF8ToUTF16(&string, string + length, &p, p + length))
+ return OpaqueJSString::create(buffer.data(), p - buffer.data()).releaseRef();
+ }
+
+ // Null string.
+ return OpaqueJSString::create().releaseRef();
}
JSStringRef JSStringRetain(JSStringRef string)
{
- JSLock lock;
- UString::Rep* rep = toJS(string);
- return toRef(rep->ref());
+ string->ref();
+ return string;
}
void JSStringRelease(JSStringRef string)
{
- JSLock lock;
- UString::Rep* rep = toJS(string);
- rep->deref();
+ string->deref();
}
size_t JSStringGetLength(JSStringRef string)
{
- UString::Rep* rep = toJS(string);
- return rep->size();
+ return string->length();
}
const JSChar* JSStringGetCharactersPtr(JSStringRef string)
{
- UString::Rep* rep = toJS(string);
- return reinterpret_cast<const JSChar*>(rep->data());
+ return string->characters();
}
size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string)
{
- UString::Rep* rep = toJS(string);
-
// Any UTF8 character > 3 bytes encodes as a UTF16 surrogate pair.
- return rep->size() * 3 + 1; // + 1 for terminating '\0'
+ return string->length() * 3 + 1; // + 1 for terminating '\0'
}
size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize)
{
- JSLock lock;
- UString::Rep* rep = toJS(string);
- CString cString = UString(rep).UTF8String();
+ if (!bufferSize)
+ return 0;
+
+ char* p = buffer;
+ const UChar* d = string->characters();
+ ConversionResult result = convertUTF16ToUTF8(&d, d + string->length(), &p, p + bufferSize - 1, true);
+ *p++ = '\0';
+ if (result != conversionOK && result != targetExhausted)
+ return 0;
- size_t length = std::min(bufferSize, cString.size() + 1); // + 1 for terminating '\0'
- memcpy(buffer, cString.c_str(), length);
- return length;
+ return p - buffer;
}
bool JSStringIsEqual(JSStringRef a, JSStringRef b)
{
- JSLock lock;
-
- UString::Rep* aRep = toJS(a);
- UString::Rep* bRep = toJS(b);
-
- return UString(aRep) == UString(bRep);
+ unsigned len = a->length();
+ return len == b->length() && 0 == memcmp(a->characters(), b->characters(), len * sizeof(UChar));
}
bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b)
diff --git a/JavaScriptCore/API/JSStringRef.h b/JavaScriptCore/API/JSStringRef.h
index fb5649f..8b17ee2 100644
--- a/JavaScriptCore/API/JSStringRef.h
+++ b/JavaScriptCore/API/JSStringRef.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -29,8 +28,10 @@
#include <JavaScriptCore/JSValueRef.h>
+#ifndef __cplusplus
#include <stdbool.h>
-#include <stddef.h> // for size_t
+#endif
+#include <stddef.h> /* for size_t */
#ifdef __cplusplus
extern "C" {
@@ -140,4 +141,4 @@ JS_EXPORT bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b);
}
#endif
-#endif // JSStringRef_h
+#endif /* JSStringRef_h */
diff --git a/JavaScriptCore/API/JSStringRefBSTR.cpp b/JavaScriptCore/API/JSStringRefBSTR.cpp
index 1a538ab..a7d3e99 100644
--- a/JavaScriptCore/API/JSStringRefBSTR.cpp
+++ b/JavaScriptCore/API/JSStringRefBSTR.cpp
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
*
diff --git a/JavaScriptCore/API/JSStringRefBSTR.h b/JavaScriptCore/API/JSStringRefBSTR.h
index 4987f83..59f19b7 100644
--- a/JavaScriptCore/API/JSStringRefBSTR.h
+++ b/JavaScriptCore/API/JSStringRefBSTR.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
*
@@ -38,7 +37,7 @@
extern "C" {
#endif
-// COM convenience methods
+/* COM convenience methods */
/*!
@function
@@ -60,4 +59,4 @@ JS_EXPORT BSTR JSStringCopyBSTR(const JSStringRef string);
}
#endif
-#endif // JSStringRefBSTR_h
+#endif /* JSStringRefBSTR_h */
diff --git a/JavaScriptCore/API/JSStringRefCF.cpp b/JavaScriptCore/API/JSStringRefCF.cpp
index 70a5aa7..3a37866 100644
--- a/JavaScriptCore/API/JSStringRefCF.cpp
+++ b/JavaScriptCore/API/JSStringRefCF.cpp
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006, 2007 Apple Computer, Inc. All rights reserved.
*
@@ -29,29 +28,25 @@
#include "APICast.h"
#include "JSStringRef.h"
-#include <kjs/JSLock.h>
+#include "OpaqueJSString.h"
#include <kjs/ustring.h>
-#include <kjs/value.h>
-
-using namespace KJS;
+#include <runtime/JSValue.h>
+#include <wtf/OwnArrayPtr.h>
JSStringRef JSStringCreateWithCFString(CFStringRef string)
{
- JSLock lock;
CFIndex length = CFStringGetLength(string);
- UString::Rep* rep;
- if (!length)
- rep = UString("").rep()->ref();
- else {
- UniChar* buffer = static_cast<UniChar*>(fastMalloc(sizeof(UniChar) * length));
- CFStringGetCharacters(string, CFRangeMake(0, length), buffer);
- rep = UString(reinterpret_cast<UChar*>(buffer), length, false).rep()->ref();
+ if (length) {
+ OwnArrayPtr<UniChar> buffer(new UniChar[length]);
+ CFStringGetCharacters(string, CFRangeMake(0, length), buffer.get());
+ COMPILE_ASSERT(sizeof(UniChar) == sizeof(UChar), unichar_and_uchar_must_be_same_size);
+ return OpaqueJSString::create(reinterpret_cast<UChar*>(buffer.get()), length).releaseRef();
+ } else {
+ return OpaqueJSString::create(0, 0).releaseRef();
+ }
}
- return toRef(rep);
-}
CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string)
{
- UString::Rep* rep = toJS(string);
- return CFStringCreateWithCharacters(alloc, reinterpret_cast<const UniChar*>(rep->data()), rep->size());
+ return CFStringCreateWithCharacters(alloc, reinterpret_cast<const UniChar*>(string->characters()), string->length());
}
diff --git a/JavaScriptCore/API/JSStringRefCF.h b/JavaScriptCore/API/JSStringRefCF.h
index ef84a9c..a424765 100644
--- a/JavaScriptCore/API/JSStringRefCF.h
+++ b/JavaScriptCore/API/JSStringRefCF.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006, 2007 Apple Computer, Inc. All rights reserved.
*
@@ -34,7 +33,7 @@
extern "C" {
#endif
-// CFString convenience methods
+/* CFString convenience methods */
/*!
@function
@@ -53,9 +52,9 @@ JS_EXPORT JSStringRef JSStringCreateWithCFString(CFStringRef string);
@result A CFString containing string. Ownership follows the Create Rule.
*/
JS_EXPORT CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string);
-
+
#ifdef __cplusplus
}
#endif
-#endif // JSStringRefCF_h
+#endif /* JSStringRefCF_h */
diff --git a/JavaScriptCore/API/JSValueRef.cpp b/JavaScriptCore/API/JSValueRef.cpp
index 468a2d1..15dd633 100644
--- a/JavaScriptCore/API/JSValueRef.cpp
+++ b/JavaScriptCore/API/JSValueRef.cpp
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
@@ -31,13 +30,12 @@
#include "APICast.h"
#include "JSCallbackObject.h"
-#include <kjs/JSType.h>
-#include <kjs/JSGlobalObject.h>
-#include <kjs/internal.h>
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSString.h>
#include <kjs/operations.h>
#include <kjs/protect.h>
#include <kjs/ustring.h>
-#include <kjs/value.h>
+#include <runtime/JSValue.h>
#include <wtf/Assertions.h>
@@ -45,27 +43,22 @@
JSType JSValueGetType(JSContextRef, JSValueRef value)
{
- KJS::JSValue* jsValue = toJS(value);
- switch (jsValue->type()) {
- case KJS::UndefinedType:
- return kJSTypeUndefined;
- case KJS::NullType:
- return kJSTypeNull;
- case KJS::BooleanType:
- return kJSTypeBoolean;
- case KJS::NumberType:
- return kJSTypeNumber;
- case KJS::StringType:
- return kJSTypeString;
- case KJS::ObjectType:
- return kJSTypeObject;
- default:
- ASSERT(!"JSValueGetType: unknown type code.\n");
- return kJSTypeUndefined;
- }
+ JSC::JSValue* jsValue = toJS(value);
+ if (jsValue->isUndefined())
+ return kJSTypeUndefined;
+ if (jsValue->isNull())
+ return kJSTypeNull;
+ if (jsValue->isBoolean())
+ return kJSTypeBoolean;
+ if (jsValue->isNumber())
+ return kJSTypeNumber;
+ if (jsValue->isString())
+ return kJSTypeString;
+ ASSERT(jsValue->isObject());
+ return kJSTypeObject;
}
-using namespace KJS; // placed here to avoid conflict between KJS::JSType and JSType, above.
+using namespace JSC; // placed here to avoid conflict between JSC::JSType and JSType, above.
bool JSValueIsUndefined(JSContextRef, JSValueRef value)
{
@@ -118,8 +111,10 @@ bool JSValueIsObjectOfClass(JSContextRef, JSValueRef value, JSClassRef jsClass)
bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSValue* jsA = toJS(a);
JSValue* jsB = toJS(b);
@@ -132,27 +127,26 @@ bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* ex
return result;
}
-bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b)
+bool JSValueIsStrictEqual(JSContextRef, JSValueRef a, JSValueRef b)
{
- JSLock lock;
- ExecState* exec = toJS(ctx);
JSValue* jsA = toJS(a);
JSValue* jsB = toJS(b);
- bool result = strictEqual(exec, jsA, jsB); // can't throw because it doesn't perform value conversion
- ASSERT(!exec->hadException());
+ bool result = strictEqual(jsA, jsB);
return result;
}
bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSValue* jsValue = toJS(value);
JSObject* jsConstructor = toJS(constructor);
- if (!jsConstructor->implementsHasInstance())
+ if (!jsConstructor->structureID()->typeInfo().implementsHasInstance())
return false;
- bool result = jsConstructor->hasInstance(exec, jsValue); // false if an exception is thrown
+ bool result = jsConstructor->hasInstance(exec, jsValue, jsConstructor->get(exec, exec->propertyNames().prototype)); // false if an exception is thrown
if (exec->hadException()) {
if (exception)
*exception = toRef(exec->exception());
@@ -176,17 +170,22 @@ JSValueRef JSValueMakeBoolean(JSContextRef, bool value)
return toRef(jsBoolean(value));
}
-JSValueRef JSValueMakeNumber(JSContextRef, double value)
+JSValueRef JSValueMakeNumber(JSContextRef ctx, double value)
{
- JSLock lock;
- return toRef(jsNumber(value));
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ return toRef(jsNumber(exec, value));
}
-JSValueRef JSValueMakeString(JSContextRef, JSStringRef string)
+JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
{
- JSLock lock;
- UString::Rep* rep = toJS(string);
- return toRef(jsString(UString(rep)));
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ return toRef(jsString(exec, string->ustring()));
}
bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
@@ -198,9 +197,11 @@ bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
{
- JSLock lock;
- JSValue* jsValue = toJS(value);
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ JSValue* jsValue = toJS(value);
double number = jsValue->toNumber(exec);
if (exec->hadException()) {
@@ -214,24 +215,28 @@ double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception
JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
{
- JSLock lock;
- JSValue* jsValue = toJS(value);
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
+ JSValue* jsValue = toJS(value);
- JSStringRef stringRef = toRef(jsValue->toString(exec).rep()->ref());
+ RefPtr<OpaqueJSString> stringRef(OpaqueJSString::create(jsValue->toString(exec)));
if (exec->hadException()) {
if (exception)
*exception = toRef(exec->exception());
exec->clearException();
- stringRef = 0;
+ stringRef.clear();
}
- return stringRef;
+ return stringRef.release().releaseRef();
}
JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
{
- JSLock lock;
ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSValue* jsValue = toJS(value);
JSObjectRef objectRef = toRef(jsValue->toObject(exec));
@@ -244,16 +249,22 @@ JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exce
return objectRef;
}
-void JSValueProtect(JSContextRef, JSValueRef value)
+void JSValueProtect(JSContextRef ctx, JSValueRef value)
{
- JSLock lock;
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSValue* jsValue = toJS(value);
gcProtect(jsValue);
}
-void JSValueUnprotect(JSContextRef, JSValueRef value)
+void JSValueUnprotect(JSContextRef ctx, JSValueRef value)
{
- JSLock lock;
+ ExecState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ JSLock lock(exec);
+
JSValue* jsValue = toJS(value);
gcUnprotect(jsValue);
}
diff --git a/JavaScriptCore/API/JSValueRef.h b/JavaScriptCore/API/JSValueRef.h
index 6f1ce08..7a7bf93 100644
--- a/JavaScriptCore/API/JSValueRef.h
+++ b/JavaScriptCore/API/JSValueRef.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -29,7 +28,9 @@
#include <JavaScriptCore/JSBase.h>
+#ifndef __cplusplus
#include <stdbool.h>
+#endif
/*!
@enum JSType
@@ -127,7 +128,7 @@ JS_EXPORT bool JSValueIsObject(JSContextRef ctx, JSValueRef value);
*/
JS_EXPORT bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass);
-// Comparing values
+/* Comparing values */
/*!
@function
@@ -161,7 +162,7 @@ JS_EXPORT bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b
*/
JS_EXPORT bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception);
-// Creating values
+/* Creating values */
/*!
@function
@@ -207,7 +208,7 @@ JS_EXPORT JSValueRef JSValueMakeNumber(JSContextRef ctx, double number);
*/
JS_EXPORT JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string);
-// Converting to primitive values
+/* Converting to primitive values */
/*!
@function
@@ -248,7 +249,7 @@ JS_EXPORT JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JS
*/
JS_EXPORT JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
-// Garbage collection
+/* Garbage collection */
/*!
@function
@abstract Protects a JavaScript value from garbage collection.
@@ -274,4 +275,4 @@ JS_EXPORT void JSValueUnprotect(JSContextRef ctx, JSValueRef value);
}
#endif
-#endif // JSValueRef_h
+#endif /* JSValueRef_h */
diff --git a/JavaScriptCore/API/JavaScript.h b/JavaScriptCore/API/JavaScript.h
index 3a6cc38..f8d92d8 100644
--- a/JavaScriptCore/API/JavaScript.h
+++ b/JavaScriptCore/API/JavaScript.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Inc. All rights reserved.
* Copyright (C) 2008 Alp Toker <alp@atoker.com>
@@ -34,4 +33,4 @@
#include <JavaScriptCore/JSObjectRef.h>
#include <JavaScriptCore/JSValueRef.h>
-#endif // JavaScript_h
+#endif /* JavaScript_h */
diff --git a/JavaScriptCore/API/JavaScriptCore.h b/JavaScriptCore/API/JavaScriptCore.h
index be6b8b2..87d6018 100644
--- a/JavaScriptCore/API/JavaScriptCore.h
+++ b/JavaScriptCore/API/JavaScriptCore.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
*
@@ -30,4 +29,4 @@
#include <JavaScriptCore/JavaScript.h>
#include <JavaScriptCore/JSStringRefCF.h>
-#endif // JavaScriptCore_h
+#endif /* JavaScriptCore_h */
diff --git a/JavaScriptCore/API/OpaqueJSString.cpp b/JavaScriptCore/API/OpaqueJSString.cpp
new file mode 100644
index 0000000..0819141
--- /dev/null
+++ b/JavaScriptCore/API/OpaqueJSString.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "OpaqueJSString.h"
+
+#include <runtime/ExecState.h>
+#include <runtime/JSGlobalObject.h>
+#include <kjs/identifier.h>
+
+using namespace JSC;
+
+PassRefPtr<OpaqueJSString> OpaqueJSString::create(const UString& ustring)
+{
+ if (!ustring.isNull())
+ return adoptRef(new OpaqueJSString(ustring.data(), ustring.size()));
+ return 0;
+}
+
+UString OpaqueJSString::ustring() const
+{
+ if (this && m_characters)
+ return UString(m_characters, m_length, true);
+ return UString::null();
+}
+
+Identifier OpaqueJSString::identifier(JSGlobalData* globalData) const
+{
+ if (!this || !m_characters)
+ return Identifier(globalData, static_cast<const char*>(0));
+
+ return Identifier(globalData, m_characters, m_length);
+}
diff --git a/JavaScriptCore/API/OpaqueJSString.h b/JavaScriptCore/API/OpaqueJSString.h
new file mode 100644
index 0000000..da05b06
--- /dev/null
+++ b/JavaScriptCore/API/OpaqueJSString.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef OpaqueJSString_h
+#define OpaqueJSString_h
+
+#include <kjs/ustring.h>
+
+namespace JSC {
+ class Identifier;
+ class JSGlobalData;
+}
+
+struct OpaqueJSString : public ThreadSafeShared<OpaqueJSString> {
+
+ static PassRefPtr<OpaqueJSString> create() // null
+ {
+ return adoptRef(new OpaqueJSString);
+ }
+
+ static PassRefPtr<OpaqueJSString> create(const UChar* characters, unsigned length)
+ {
+ return adoptRef(new OpaqueJSString(characters, length));
+ }
+
+ static PassRefPtr<OpaqueJSString> create(const JSC::UString&);
+
+ UChar* characters() { return this ? m_characters : 0; }
+ unsigned length() { return this ? m_length : 0; }
+
+ JSC::UString ustring() const;
+ JSC::Identifier identifier(JSC::JSGlobalData*) const;
+
+private:
+ friend class WTF::ThreadSafeShared<OpaqueJSString>;
+
+ OpaqueJSString()
+ : m_characters(0)
+ , m_length(0)
+ {
+ }
+
+ OpaqueJSString(const UChar* characters, unsigned length)
+ : m_length(length)
+ {
+ m_characters = new UChar[length];
+ memcpy(m_characters, characters, length * sizeof(UChar));
+ }
+
+ ~OpaqueJSString()
+ {
+ delete[] m_characters;
+ }
+
+ UChar* m_characters;
+ unsigned m_length;
+};
+
+#endif
diff --git a/JavaScriptCore/API/WebKitAvailability.h b/JavaScriptCore/API/WebKitAvailability.h
new file mode 100644
index 0000000..fae3904
--- /dev/null
+++ b/JavaScriptCore/API/WebKitAvailability.h
@@ -0,0 +1,761 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __WebKitAvailability__
+#define __WebKitAvailability__
+
+/* The structure of this header is based on AvailabilityMacros.h. The major difference is that the availability
+ macros are defined in terms of WebKit version numbers rather than Mac OS X system version numbers, as WebKit
+ releases span multiple versions of Mac OS X.
+*/
+
+#define WEBKIT_VERSION_1_0 0x0100
+#define WEBKIT_VERSION_1_1 0x0110
+#define WEBKIT_VERSION_1_2 0x0120
+#define WEBKIT_VERSION_1_3 0x0130
+#define WEBKIT_VERSION_2_0 0x0200
+#define WEBKIT_VERSION_3_0 0x0300
+#define WEBKIT_VERSION_3_1 0x0310
+#define WEBKIT_VERSION_LATEST 0x9999
+
+#ifdef __APPLE__
+#import <AvailabilityMacros.h>
+#else
+// For non-Mac platforms, require the newest version.
+#define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_LATEST
+/*
+ * only certain compilers support __attribute__((deprecated))
+ */
+#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
+ #define DEPRECATED_ATTRIBUTE __attribute__((deprecated))
+#else
+ #define DEPRECATED_ATTRIBUTE
+#endif
+#endif
+
+/* The versions of GCC that shipped with Xcode prior to 3.0 (GCC build number < 5400) did not support attributes on methods.
+ If we are building with one of these versions, we need to omit the attribute. We achieve this by wrapping the annotation
+ in WEBKIT_OBJC_METHOD_ANNOTATION, which will remove the annotation when an old version of GCC is in use and will otherwise
+ expand to the annotation. The same is needed for protocol methods.
+*/
+#if defined(__APPLE_CC__) && __APPLE_CC__ < 5400
+ #define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION)
+#else
+ #define WEBKIT_OBJC_METHOD_ANNOTATION(ANNOTATION) ANNOTATION
+#endif
+
+
+/* If minimum WebKit version is not specified, assume the version that shipped with the target Mac OS X version */
+#ifndef WEBKIT_VERSION_MIN_REQUIRED
+ #if !defined(MAC_OS_X_VERSION_10_2) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_2
+ #error WebKit was not available prior to Mac OS X 10.2
+ #elif !defined(MAC_OS_X_VERSION_10_3) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3
+ /* WebKit 1.0 is the only version available on Mac OS X 10.2. */
+ #define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_1_0
+ #elif !defined(MAC_OS_X_VERSION_10_4) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
+ /* WebKit 1.1 is the version that shipped on Mac OS X 10.3. */
+ #define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_1_1
+ #elif !defined(MAC_OS_X_VERSION_10_5) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
+ /* WebKit 2.0 is the version that shipped on Mac OS X 10.4. */
+ #define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_2_0
+ #elif !defined(MAC_OS_X_VERSION_10_6) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
+ /* WebKit 3.0 is the version that shipped on Mac OS X 10.5. */
+ #define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_3_0
+ #else
+ #define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_LATEST
+ #endif
+#endif
+
+
+/* If maximum WebKit version is not specified, assume largerof(latest, minimum) */
+#ifndef WEBKIT_VERSION_MAX_ALLOWED
+ #if WEBKIT_VERSION_MIN_REQUIRED > WEBKIT_VERSION_LATEST
+ #define WEBKIT_VERSION_MAX_ALLOWED WEBKIT_VERSION_MIN_REQUIRED
+ #else
+ #define WEBKIT_VERSION_MAX_ALLOWED WEBKIT_VERSION_LATEST
+ #endif
+#endif
+
+
+/* Sanity check the configured values */
+#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_MIN_REQUIRED
+ #error WEBKIT_VERSION_MAX_ALLOWED must be >= WEBKIT_VERSION_MIN_REQUIRED
+#endif
+#if WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_1_0
+ #error WEBKIT_VERSION_MIN_REQUIRED must be >= WEBKIT_VERSION_1_0
+#endif
+
+
+
+
+
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER
+ *
+ * Used on functions introduced in WebKit 1.0
+ */
+#define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED
+ *
+ * Used on functions introduced in WebKit 1.0,
+ * and deprecated in WebKit 1.0
+ */
+#define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+
+/*
+ * DEPRECATED_IN_WEBKIT_VERSION_1_0_AND_LATER
+ *
+ * Used on types deprecated in WebKit 1.0
+ */
+#define DEPRECATED_IN_WEBKIT_VERSION_1_0_AND_LATER DEPRECATED_ATTRIBUTE
+
+
+
+
+
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER
+ *
+ * Used on declarations introduced in WebKit 1.1
+ */
+#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_1_1
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER UNAVAILABLE_ATTRIBUTE
+#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_1_1
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER WEAK_IMPORT_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED
+ *
+ * Used on declarations introduced in WebKit 1.1,
+ * and deprecated in WebKit 1.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_1
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_1
+ *
+ * Used on declarations introduced in WebKit 1.0,
+ * but later deprecated in WebKit 1.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_1
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_1 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER
+#endif
+
+/*
+ * DEPRECATED_IN_WEBKIT_VERSION_1_1_AND_LATER
+ *
+ * Used on types deprecated in WebKit 1.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_1
+ #define DEPRECATED_IN_WEBKIT_VERSION_1_1_AND_LATER DEPRECATED_ATTRIBUTE
+#else
+ #define DEPRECATED_IN_WEBKIT_VERSION_1_1_AND_LATER
+#endif
+
+
+
+
+
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER
+ *
+ * Used on declarations introduced in WebKit 1.2
+ */
+#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_1_2
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER UNAVAILABLE_ATTRIBUTE
+#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_1_2
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER WEAK_IMPORT_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED
+ *
+ * Used on declarations introduced in WebKit 1.2,
+ * and deprecated in WebKit 1.2
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_2
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2
+ *
+ * Used on declarations introduced in WebKit 1.0,
+ * but later deprecated in WebKit 1.2
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_2
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2
+ *
+ * Used on declarations introduced in WebKit 1.1,
+ * but later deprecated in WebKit 1.2
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_2
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_2 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER
+#endif
+
+/*
+ * DEPRECATED_IN_WEBKIT_VERSION_1_2_AND_LATER
+ *
+ * Used on types deprecated in WebKit 1.2
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_2
+ #define DEPRECATED_IN_WEBKIT_VERSION_1_2_AND_LATER DEPRECATED_ATTRIBUTE
+#else
+ #define DEPRECATED_IN_WEBKIT_VERSION_1_2_AND_LATER
+#endif
+
+
+
+
+
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER
+ *
+ * Used on declarations introduced in WebKit 1.3
+ */
+#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_1_3
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER UNAVAILABLE_ATTRIBUTE
+#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_1_3
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER WEAK_IMPORT_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED
+ *
+ * Used on declarations introduced in WebKit 1.3,
+ * and deprecated in WebKit 1.3
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_3
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3
+ *
+ * Used on declarations introduced in WebKit 1.0,
+ * but later deprecated in WebKit 1.3
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_3
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3
+ *
+ * Used on declarations introduced in WebKit 1.1,
+ * but later deprecated in WebKit 1.3
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_3
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3
+ *
+ * Used on declarations introduced in WebKit 1.2,
+ * but later deprecated in WebKit 1.3
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_3
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_1_3 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER
+#endif
+
+/*
+ * DEPRECATED_IN_WEBKIT_VERSION_1_3_AND_LATER
+ *
+ * Used on types deprecated in WebKit 1.3
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_1_3
+ #define DEPRECATED_IN_WEBKIT_VERSION_1_3_AND_LATER DEPRECATED_ATTRIBUTE
+#else
+ #define DEPRECATED_IN_WEBKIT_VERSION_1_3_AND_LATER
+#endif
+
+
+
+
+
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER
+ *
+ * Used on declarations introduced in WebKit 2.0
+ */
+#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_2_0
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER UNAVAILABLE_ATTRIBUTE
+#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_2_0
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER WEAK_IMPORT_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED
+ *
+ * Used on declarations introduced in WebKit 2.0,
+ * and deprecated in WebKit 2.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0
+ *
+ * Used on declarations introduced in WebKit 1.0,
+ * but later deprecated in WebKit 2.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0
+ *
+ * Used on declarations introduced in WebKit 1.1,
+ * but later deprecated in WebKit 2.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0
+ *
+ * Used on declarations introduced in WebKit 1.2,
+ * but later deprecated in WebKit 2.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0
+ *
+ * Used on declarations introduced in WebKit 1.3,
+ * but later deprecated in WebKit 2.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_2_0 AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER
+#endif
+
+/*
+ * DEPRECATED_IN_WEBKIT_VERSION_2_0_AND_LATER
+ *
+ * Used on types deprecated in WebKit 2.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_2_0
+ #define DEPRECATED_IN_WEBKIT_VERSION_2_0_AND_LATER DEPRECATED_ATTRIBUTE
+#else
+ #define DEPRECATED_IN_WEBKIT_VERSION_2_0_AND_LATER
+#endif
+
+
+
+
+
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER
+ *
+ * Used on declarations introduced in WebKit 3.0
+ */
+#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_3_0
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER UNAVAILABLE_ATTRIBUTE
+#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_3_0
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER WEAK_IMPORT_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED
+ *
+ * Used on declarations introduced in WebKit 3.0,
+ * and deprecated in WebKit 3.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0
+ *
+ * Used on declarations introduced in WebKit 1.0,
+ * but later deprecated in WebKit 3.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0
+ *
+ * Used on declarations introduced in WebKit 1.1,
+ * but later deprecated in WebKit 3.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0
+ *
+ * Used on declarations introduced in WebKit 1.2,
+ * but later deprecated in WebKit 3.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0
+ *
+ * Used on declarations introduced in WebKit 1.3,
+ * but later deprecated in WebKit 3.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0
+ *
+ * Used on declarations introduced in WebKit 2.0,
+ * but later deprecated in WebKit 3.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0 AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER
+#endif
+
+/*
+ * DEPRECATED_IN_WEBKIT_VERSION_3_0_AND_LATER
+ *
+ * Used on types deprecated in WebKit 3.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_0
+ #define DEPRECATED_IN_WEBKIT_VERSION_3_0_AND_LATER DEPRECATED_ATTRIBUTE
+#else
+ #define DEPRECATED_IN_WEBKIT_VERSION_3_0_AND_LATER
+#endif
+
+
+
+
+
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER
+ *
+ * Used on declarations introduced in WebKit 3.1
+ */
+#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_3_1
+ #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER UNAVAILABLE_ATTRIBUTE
+#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_3_1
+ #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER WEAK_IMPORT_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED
+ *
+ * Used on declarations introduced in WebKit 3.1,
+ * and deprecated in WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1
+ #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 1.0,
+ * but later deprecated in WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 1.1,
+ * but later deprecated in WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 1.2,
+ * but later deprecated in WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 1.3,
+ * but later deprecated in WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 2.0,
+ * but later deprecated in WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 3.0,
+ * but later deprecated in WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER
+#endif
+
+/*
+ * DEPRECATED_IN_WEBKIT_VERSION_3_1_AND_LATER
+ *
+ * Used on types deprecated in WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_3_1
+ #define DEPRECATED_IN_WEBKIT_VERSION_3_1_AND_LATER DEPRECATED_ATTRIBUTE
+#else
+ #define DEPRECATED_IN_WEBKIT_VERSION_3_1_AND_LATER
+#endif
+
+
+
+
+
+
+/*
+ * AVAILABLE_AFTER_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced after WebKit 3.1
+ */
+#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_LATEST
+ #define AVAILABLE_AFTER_WEBKIT_VERSION_3_1 UNAVAILABLE_ATTRIBUTE
+#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_LATEST
+ #define AVAILABLE_AFTER_WEBKIT_VERSION_3_1 WEAK_IMPORT_ATTRIBUTE
+#else
+ #define AVAILABLE_AFTER_WEBKIT_VERSION_3_1
+#endif
+
+/*
+ * AVAILABLE_AFTER_WEBKIT_VERSION_3_1_BUT_DEPRECATED
+ *
+ * Used on declarations introduced after WebKit 3.1,
+ * and deprecated after WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_AFTER_WEBKIT_VERSION_3_1_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_AFTER_WEBKIT_VERSION_3_1_BUT_DEPRECATED AVAILABLE_AFTER_WEBKIT_VERSION_3_1
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 1.0,
+ * but later deprecated after WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 1.1,
+ * but later deprecated after WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 1.2,
+ * but later deprecated after WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 1.3,
+ * but later deprecated after WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 2.0,
+ * but later deprecated after WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 3.0,
+ * but later deprecated after WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1
+ *
+ * Used on declarations introduced in WebKit 3.1,
+ * but later deprecated after WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_3_1 AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER
+#endif
+
+/*
+ * DEPRECATED_AFTER_WEBKIT_VERSION_3_1
+ *
+ * Used on types deprecated after WebKit 3.1
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define DEPRECATED_AFTER_WEBKIT_VERSION_3_1 DEPRECATED_ATTRIBUTE
+#else
+ #define DEPRECATED_AFTER_WEBKIT_VERSION_3_1
+#endif
+
+
+#endif /* __WebKitAvailability__ */
diff --git a/JavaScriptCore/API/JSNode.c b/JavaScriptCore/API/tests/JSNode.c
index c1f6294..d9ac0a9 100644
--- a/JavaScriptCore/API/JSNode.c
+++ b/JavaScriptCore/API/tests/JSNode.c
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -38,7 +37,7 @@ static JSValueRef JSNode_appendChild(JSContextRef context, JSObjectRef function,
{
UNUSED_PARAM(function);
- // Example of throwing a type error for invalid values
+ /* Example of throwing a type error for invalid values */
if (!JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
JSStringRef message = JSStringCreateWithUTF8CString("TypeError: appendChild can only be called on nodes");
*exception = JSValueMakeString(context, message);
@@ -60,8 +59,8 @@ static JSValueRef JSNode_appendChild(JSContextRef context, JSObjectRef function,
static JSValueRef JSNode_removeChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
UNUSED_PARAM(function);
-
- // Example of ignoring invalid values
+
+ /* Example of ignoring invalid values */
if (argumentCount > 0) {
if (JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
if (JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
diff --git a/JavaScriptCore/API/JSNode.h b/JavaScriptCore/API/tests/JSNode.h
index cd3a441..7725733 100644
--- a/JavaScriptCore/API/JSNode.h
+++ b/JavaScriptCore/API/tests/JSNode.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -35,4 +34,4 @@ extern JSObjectRef JSNode_new(JSContextRef context, Node* node);
extern JSClassRef JSNode_class(JSContextRef context);
extern JSObjectRef JSNode_construct(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-#endif // JSNode_h
+#endif /* JSNode_h */
diff --git a/JavaScriptCore/API/JSNodeList.c b/JavaScriptCore/API/tests/JSNodeList.c
index 0da7c8d..bc4a8ad 100644
--- a/JavaScriptCore/API/JSNodeList.c
+++ b/JavaScriptCore/API/tests/JSNodeList.c
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -72,7 +71,7 @@ static JSValueRef JSNodeList_getProperty(JSContextRef context, JSObjectRef thisO
ASSERT(nodeList);
double index = JSValueToNumber(context, JSValueMakeString(context, propertyName), exception);
unsigned uindex = (unsigned)index;
- if (uindex == index) { // false for NaN
+ if (uindex == index) { /* false for NaN */
Node* node = NodeList_item(nodeList, uindex);
if (node)
return JSNode_new(context, node);
diff --git a/JavaScriptCore/API/JSNodeList.h b/JavaScriptCore/API/tests/JSNodeList.h
index 0bc5f74..f930914 100644
--- a/JavaScriptCore/API/JSNodeList.h
+++ b/JavaScriptCore/API/tests/JSNodeList.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -32,4 +31,4 @@
extern JSObjectRef JSNodeList_new(JSContextRef, NodeList*);
-#endif // JSNodeList_h
+#endif /* JSNodeList_h */
diff --git a/JavaScriptCore/API/Node.c b/JavaScriptCore/API/tests/Node.c
index 3ff82e2..913da0a 100644
--- a/JavaScriptCore/API/Node.c
+++ b/JavaScriptCore/API/tests/Node.c
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -49,7 +48,7 @@ void Node_appendChild(Node* node, Node* child)
void Node_removeChild(Node* node, Node* child)
{
- // Linear search from tail -- good enough for our purposes here
+ /* Linear search from tail -- good enough for our purposes here */
NodeLink* current;
NodeLink** currentHandle;
for (currentHandle = &node->childNodesTail, current = *currentHandle; current; currentHandle = &current->prev, current = *currentHandle) {
@@ -64,7 +63,7 @@ void Node_removeChild(Node* node, Node* child)
void Node_replaceChild(Node* node, Node* newChild, Node* oldChild)
{
- // Linear search from tail -- good enough for our purposes here
+ /* Linear search from tail -- good enough for our purposes here */
NodeLink* current;
for (current = node->childNodesTail; current; current = current->prev) {
if (current->node == oldChild) {
diff --git a/JavaScriptCore/API/Node.h b/JavaScriptCore/API/tests/Node.h
index 04b2c70..e9250b3 100644
--- a/JavaScriptCore/API/Node.h
+++ b/JavaScriptCore/API/tests/Node.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -48,4 +47,4 @@ extern void Node_appendChild(Node* node, Node* child);
extern void Node_removeChild(Node* node, Node* child);
extern void Node_replaceChild(Node* node, Node* newChild, Node* oldChild);
-#endif // Node_h
+#endif /* Node_h */
diff --git a/JavaScriptCore/API/NodeList.c b/JavaScriptCore/API/tests/NodeList.c
index 21b2c62..ae4c170 100644
--- a/JavaScriptCore/API/NodeList.c
+++ b/JavaScriptCore/API/tests/NodeList.c
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -31,7 +30,7 @@
extern NodeList* NodeList_new(Node* parentNode)
{
Node_ref(parentNode);
-
+
NodeList* nodeList = (NodeList*)malloc(sizeof(NodeList));
nodeList->parentNode = parentNode;
nodeList->refCount = 0;
@@ -40,7 +39,7 @@ extern NodeList* NodeList_new(Node* parentNode)
extern unsigned NodeList_length(NodeList* nodeList)
{
- // Linear count from tail -- good enough for our purposes here
+ /* Linear count from tail -- good enough for our purposes here */
unsigned i = 0;
NodeLink* n = nodeList->parentNode->childNodesTail;
while (n) {
@@ -56,8 +55,8 @@ extern Node* NodeList_item(NodeList* nodeList, unsigned index)
unsigned length = NodeList_length(nodeList);
if (index >= length)
return NULL;
-
- // Linear search from tail -- good enough for our purposes here
+
+ /* Linear search from tail -- good enough for our purposes here */
NodeLink* n = nodeList->parentNode->childNodesTail;
unsigned i = 0;
unsigned count = length - 1 - index;
diff --git a/JavaScriptCore/API/NodeList.h b/JavaScriptCore/API/tests/NodeList.h
index 289d206..25b95bf 100644
--- a/JavaScriptCore/API/NodeList.h
+++ b/JavaScriptCore/API/tests/NodeList.h
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -40,4 +39,4 @@ extern Node* NodeList_item(NodeList*, unsigned);
extern void NodeList_ref(NodeList*);
extern void NodeList_deref(NodeList*);
-#endif // NodeList_h
+#endif /* NodeList_h */
diff --git a/JavaScriptCore/API/minidom.c b/JavaScriptCore/API/tests/minidom.c
index cfbaaa0..43ae2c1 100644
--- a/JavaScriptCore/API/minidom.c
+++ b/JavaScriptCore/API/tests/minidom.c
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2007 Alp Toker <alp@atoker.com>
@@ -39,10 +38,12 @@ static JSValueRef print(JSContextRef context, JSObjectRef object, JSObjectRef th
int main(int argc, char* argv[])
{
- UNUSED_PARAM(argc);
- UNUSED_PARAM(argv);
+ const char *scriptPath = "minidom.js";
+ if (argc > 1) {
+ scriptPath = argv[1];
+ }
- JSGlobalContextRef context = JSGlobalContextCreate(NULL);
+ JSGlobalContextRef context = JSGlobalContextCreateInGroup(NULL, NULL);
JSObjectRef globalObject = JSContextGetGlobalObject(context);
JSStringRef printIString = JSStringCreateWithUTF8CString("print");
@@ -53,10 +54,10 @@ int main(int argc, char* argv[])
JSObjectSetProperty(context, globalObject, node, JSObjectMakeConstructor(context, JSNode_class(context), JSNode_construct), kJSPropertyAttributeNone, NULL);
JSStringRelease(node);
- char* scriptUTF8 = createStringWithContentsOfFile("minidom.js");
+ char* scriptUTF8 = createStringWithContentsOfFile(scriptPath);
JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
JSValueRef exception;
- JSValueRef result = JSEvaluateScript(context, script, NULL, NULL, 0, &exception);
+ JSValueRef result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
if (result)
printf("PASS: Test script executed successfully.\n");
else {
@@ -74,7 +75,6 @@ int main(int argc, char* argv[])
globalObject = 0;
JSGlobalContextRelease(context);
- JSGarbageCollect(context);
printf("PASS: Program exited normally.\n");
return 0;
}
@@ -111,7 +111,7 @@ static char* createStringWithContentsOfFile(const char* fileName)
while (!feof(f) && !ferror(f)) {
buffer_size += fread(buffer + buffer_size, 1, buffer_capacity - buffer_size, f);
- if (buffer_size == buffer_capacity) { // guarantees space for trailing '\0'
+ if (buffer_size == buffer_capacity) { /* guarantees space for trailing '\0' */
buffer_capacity *= 2;
buffer = (char*)realloc(buffer, buffer_capacity);
ASSERT(buffer);
diff --git a/JavaScriptCore/API/minidom.html b/JavaScriptCore/API/tests/minidom.html
index 7ea4747..7ea4747 100644
--- a/JavaScriptCore/API/minidom.html
+++ b/JavaScriptCore/API/tests/minidom.html
diff --git a/JavaScriptCore/API/minidom.js b/JavaScriptCore/API/tests/minidom.js
index 7624d39..4808960 100644
--- a/JavaScriptCore/API/minidom.js
+++ b/JavaScriptCore/API/tests/minidom.js
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
diff --git a/JavaScriptCore/API/testapi.c b/JavaScriptCore/API/tests/testapi.c
index 850aed8..48c8583 100644
--- a/JavaScriptCore/API/testapi.c
+++ b/JavaScriptCore/API/tests/testapi.c
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -25,10 +24,22 @@
*/
#include "JavaScriptCore.h"
+#include "JSBasePrivate.h"
#include <math.h>
#include <wtf/Assertions.h>
#include <wtf/UnusedParam.h>
+#if COMPILER(MSVC)
+
+#include <wtf/MathExtras.h>
+
+static double nan(const char*)
+{
+ return std::numeric_limits<double>::quiet_NaN();
+}
+
+#endif
+
static JSGlobalContextRef context = 0;
static void assertEqualsAsBoolean(JSValueRef value, bool expectedValue)
@@ -53,7 +64,7 @@ static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue
JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL);
size_t jsSize = JSStringGetMaximumUTF8CStringSize(valueAsString);
- char jsBuffer[jsSize];
+ char* jsBuffer = (char*)malloc(jsSize);
JSStringGetUTF8CString(valueAsString, jsBuffer, jsSize);
unsigned i;
@@ -64,6 +75,7 @@ static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue
if (jsSize < strlen(jsBuffer) + 1)
fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n");
+ free(jsBuffer);
JSStringRelease(valueAsString);
}
@@ -78,7 +90,7 @@ static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedVa
expectedValue,
kCFStringEncodingUTF8);
CFIndex cfLength = CFStringGetLength(expectedValueAsCFString);
- UniChar cfBuffer[cfLength];
+ UniChar* cfBuffer = (UniChar*)malloc(cfLength * sizeof(UniChar));
CFStringGetCharacters(expectedValueAsCFString, CFRangeMake(0, cfLength), cfBuffer);
CFRelease(expectedValueAsCFString);
@@ -88,6 +100,7 @@ static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedVa
if (jsLength != (size_t)cfLength)
fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
+ free(cfBuffer);
JSStringRelease(valueAsString);
}
@@ -225,6 +238,13 @@ static JSValueRef MyObject_convertToType(JSContextRef context, JSObjectRef objec
switch (type) {
case kJSTypeNumber:
return JSValueMakeNumber(context, 1);
+ case kJSTypeString:
+ {
+ JSStringRef string = JSStringCreateWithUTF8CString("MyObjectAsString");
+ JSValueRef result = JSValueMakeString(context, string);
+ JSStringRelease(string);
+ return result;
+ }
default:
break;
}
@@ -443,9 +463,10 @@ static JSValueRef print_callAsFunction(JSContextRef context, JSObjectRef functio
if (argumentCount > 0) {
JSStringRef string = JSValueToStringCopy(context, arguments[0], NULL);
size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
- char stringUTF8[sizeUTF8];
+ char* stringUTF8 = (char*)malloc(sizeUTF8);
JSStringGetUTF8CString(string, stringUTF8, sizeUTF8);
printf("%s\n", stringUTF8);
+ free(stringUTF8);
JSStringRelease(string);
}
@@ -539,15 +560,16 @@ static void testInitializeFinalize()
int main(int argc, char* argv[])
{
- UNUSED_PARAM(argc);
- UNUSED_PARAM(argv);
+ const char *scriptPath = "testapi.js";
+ if (argc > 1) {
+ scriptPath = argv[1];
+ }
// Test garbage collection with a fresh context
- context = JSGlobalContextCreate(NULL);
+ context = JSGlobalContextCreateInGroup(NULL, NULL);
TestInitializeFinalize = true;
testInitializeFinalize();
JSGlobalContextRelease(context);
- JSGarbageCollect(context);
TestInitializeFinalize = false;
ASSERT(Base_didFinalize);
@@ -558,8 +580,15 @@ int main(int argc, char* argv[])
globalObjectClassDefinition.staticFunctions = globalObject_staticFunctions;
globalObjectClassDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
JSClassRef globalObjectClass = JSClassCreate(&globalObjectClassDefinition);
- context = JSGlobalContextCreate(globalObjectClass);
+ context = JSGlobalContextCreateInGroup(NULL, globalObjectClass);
+
+ JSGlobalContextRetain(context);
+ JSGlobalContextRelease(context);
+ JSReportExtraMemoryCost(context, 0);
+ JSReportExtraMemoryCost(context, 1);
+ JSReportExtraMemoryCost(context, 1024);
+
JSObjectRef globalObject = JSContextGetGlobalObject(context);
ASSERT(JSValueIsObject(context, globalObject));
@@ -597,14 +626,15 @@ int main(int argc, char* argv[])
JSValueRef jsCFEmptyString = JSValueMakeString(context, jsCFEmptyIString);
CFIndex cfStringLength = CFStringGetLength(cfString);
- UniChar buffer[cfStringLength];
+ UniChar* buffer = (UniChar*)malloc(cfStringLength * sizeof(UniChar));
CFStringGetCharacters(cfString,
CFRangeMake(0, cfStringLength),
buffer);
- JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters(buffer, cfStringLength);
+ JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters((JSChar*)buffer, cfStringLength);
JSValueRef jsCFStringWithCharacters = JSValueMakeString(context, jsCFIStringWithCharacters);
- JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters(buffer, CFStringGetLength(cfEmptyString));
+ JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters((JSChar*)buffer, CFStringGetLength(cfEmptyString));
+ free(buffer);
JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(context, jsCFEmptyIStringWithCharacters);
ASSERT(JSValueGetType(context, jsUndefined) == kJSTypeUndefined);
@@ -782,7 +812,7 @@ int main(int argc, char* argv[])
ASSERT(!JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &exception));
ASSERT(JSValueIsObject(context, exception));
v = JSObjectGetProperty(context, JSValueToObject(context, exception, NULL), line, NULL);
- assertEqualsAsNumber(v, 2); // FIXME: Lexer::setCode bumps startingLineNumber by 1 -- we need to change internal callers so that it doesn't have to (saying '0' to mean '1' in the API would be really confusing -- it's really confusing internally, in fact)
+ assertEqualsAsNumber(v, 1);
JSStringRelease(functionBody);
JSStringRelease(line);
@@ -816,7 +846,7 @@ int main(int argc, char* argv[])
JSStringRelease(functionBody);
string = JSValueToStringCopy(context, function, NULL);
- assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) \n{\n return foo;\n}");
+ assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) {return foo;}");
JSStringRelease(string);
JSStringRef print = JSStringCreateWithUTF8CString("print");
@@ -851,6 +881,39 @@ int main(int argc, char* argv[])
JSPropertyNameArrayRelease(nameArray);
ASSERT(count == 1); // jsCFString should not be enumerated
+ JSValueRef argumentsArrayValues[] = { JSValueMakeNumber(context, 10), JSValueMakeNumber(context, 20) };
+ o = JSObjectMakeArray(context, sizeof(argumentsArrayValues) / sizeof(JSValueRef), argumentsArrayValues, NULL);
+ string = JSStringCreateWithUTF8CString("length");
+ v = JSObjectGetProperty(context, o, string, NULL);
+ assertEqualsAsNumber(v, 2);
+ v = JSObjectGetPropertyAtIndex(context, o, 0, NULL);
+ assertEqualsAsNumber(v, 10);
+ v = JSObjectGetPropertyAtIndex(context, o, 1, NULL);
+ assertEqualsAsNumber(v, 20);
+
+ o = JSObjectMakeArray(context, 0, NULL, NULL);
+ v = JSObjectGetProperty(context, o, string, NULL);
+ assertEqualsAsNumber(v, 0);
+ JSStringRelease(string);
+
+ JSValueRef argumentsDateValues[] = { JSValueMakeNumber(context, 0) };
+ o = JSObjectMakeDate(context, 1, argumentsDateValues, NULL);
+ assertEqualsAsUTF8String(o, "Wed Dec 31 1969 16:00:00 GMT-0800 (PST)");
+
+ string = JSStringCreateWithUTF8CString("an error message");
+ JSValueRef argumentsErrorValues[] = { JSValueMakeString(context, string) };
+ o = JSObjectMakeError(context, 1, argumentsErrorValues, NULL);
+ assertEqualsAsUTF8String(o, "Error: an error message");
+ JSStringRelease(string);
+
+ string = JSStringCreateWithUTF8CString("foo");
+ JSStringRef string2 = JSStringCreateWithUTF8CString("gi");
+ JSValueRef argumentsRegExpValues[] = { JSValueMakeString(context, string), JSValueMakeString(context, string2) };
+ o = JSObjectMakeRegExp(context, 2, argumentsRegExpValues, NULL);
+ assertEqualsAsUTF8String(o, "/foo/gi");
+ JSStringRelease(string);
+ JSStringRelease(string2);
+
JSClassDefinition nullDefinition = kJSClassDefinitionEmpty;
nullDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
JSClassRef nullClass = JSClassCreate(&nullDefinition);
@@ -867,12 +930,34 @@ int main(int argc, char* argv[])
ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL);
ASSERT(JSValueIsEqual(context, v, o, NULL));
-
- char* scriptUTF8 = createStringWithContentsOfFile("testapi.js");
+
+ functionBody = JSStringCreateWithUTF8CString("return eval(\"this\");");
+ function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, NULL);
+ JSStringRelease(functionBody);
+ v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
+ ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
+ v = JSObjectCallAsFunction(context, function, o, 0, NULL, NULL);
+ ASSERT(JSValueIsEqual(context, v, o, NULL));
+
+ JSStringRef script = JSStringCreateWithUTF8CString("this;");
+ v = JSEvaluateScript(context, script, NULL, NULL, 1, NULL);
+ ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
+ v = JSEvaluateScript(context, script, o, NULL, 1, NULL);
+ ASSERT(JSValueIsEqual(context, v, o, NULL));
+ JSStringRelease(script);
+
+ script = JSStringCreateWithUTF8CString("eval(this);");
+ v = JSEvaluateScript(context, script, NULL, NULL, 1, NULL);
+ ASSERT(JSValueIsEqual(context, v, globalObject, NULL));
+ v = JSEvaluateScript(context, script, o, NULL, 1, NULL);
+ ASSERT(JSValueIsEqual(context, v, o, NULL));
+ JSStringRelease(script);
+
+ char* scriptUTF8 = createStringWithContentsOfFile(scriptPath);
if (!scriptUTF8)
printf("FAIL: Test script could not be loaded.\n");
else {
- JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
+ script = JSStringCreateWithUTF8CString(scriptUTF8);
result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
if (JSValueIsUndefined(context, result))
printf("PASS: Test script executed successfully.\n");
@@ -904,7 +989,6 @@ int main(int argc, char* argv[])
JSStringRelease(badSyntax);
JSGlobalContextRelease(context);
- JSGarbageCollect(context);
JSClassRelease(globalObjectClass);
printf("PASS: Program exited normally.\n");
diff --git a/JavaScriptCore/API/testapi.js b/JavaScriptCore/API/tests/testapi.js
index 52bcb71..9c8ca9e 100644
--- a/JavaScriptCore/API/testapi.js
+++ b/JavaScriptCore/API/tests/testapi.js
@@ -1,4 +1,3 @@
-// -*- mode: c++; c-basic-offset: 4 -*-
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
*
@@ -100,6 +99,7 @@ shouldBe("typeof myObject", "object");
shouldBe("MyObject ? 1 : 0", true); // toBoolean
shouldBe("+MyObject", 1); // toNumber
shouldBe("(MyObject.toString())", "[object MyObject]"); // toString
+shouldBe("String(MyObject)", "MyObjectAsString"); // type conversion to string
shouldBe("MyObject - 0", NaN); // toPrimitive
shouldBe("typeof MyConstructor", "object");