summaryrefslogtreecommitdiffstats
path: root/Source/JavaScriptCore/API
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2011-05-06 11:45:16 +0100
committerSteve Block <steveblock@google.com>2011-05-12 13:44:10 +0100
commitcad810f21b803229eb11403f9209855525a25d57 (patch)
tree29a6fd0279be608e0fe9ffe9841f722f0f4e4269 /Source/JavaScriptCore/API
parent121b0cf4517156d0ac5111caf9830c51b69bae8f (diff)
downloadexternal_webkit-cad810f21b803229eb11403f9209855525a25d57.zip
external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.gz
external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.bz2
Merge WebKit at r75315: Initial merge by git.
Change-Id: I570314b346ce101c935ed22a626b48c2af266b84
Diffstat (limited to 'Source/JavaScriptCore/API')
-rw-r--r--Source/JavaScriptCore/API/APICast.h153
-rw-r--r--Source/JavaScriptCore/API/APIShims.h101
-rw-r--r--Source/JavaScriptCore/API/JSBase.cpp113
-rw-r--r--Source/JavaScriptCore/API/JSBase.h132
-rw-r--r--Source/JavaScriptCore/API/JSBasePrivate.h52
-rw-r--r--Source/JavaScriptCore/API/JSCallbackConstructor.cpp89
-rw-r--r--Source/JavaScriptCore/API/JSCallbackConstructor.h60
-rw-r--r--Source/JavaScriptCore/API/JSCallbackFunction.cpp80
-rw-r--r--Source/JavaScriptCore/API/JSCallbackFunction.h58
-rw-r--r--Source/JavaScriptCore/API/JSCallbackObject.cpp42
-rw-r--r--Source/JavaScriptCore/API/JSCallbackObject.h201
-rw-r--r--Source/JavaScriptCore/API/JSCallbackObjectFunctions.h607
-rw-r--r--Source/JavaScriptCore/API/JSClassRef.cpp266
-rw-r--r--Source/JavaScriptCore/API/JSClassRef.h122
-rw-r--r--Source/JavaScriptCore/API/JSContextRef.cpp175
-rw-r--r--Source/JavaScriptCore/API/JSContextRef.h132
-rw-r--r--Source/JavaScriptCore/API/JSContextRefPrivate.h53
-rw-r--r--Source/JavaScriptCore/API/JSObjectRef.cpp544
-rw-r--r--Source/JavaScriptCore/API/JSObjectRef.h694
-rw-r--r--Source/JavaScriptCore/API/JSObjectRefPrivate.h74
-rw-r--r--Source/JavaScriptCore/API/JSProfilerPrivate.cpp46
-rw-r--r--Source/JavaScriptCore/API/JSProfilerPrivate.h63
-rw-r--r--Source/JavaScriptCore/API/JSRetainPtr.h208
-rw-r--r--Source/JavaScriptCore/API/JSStringRef.cpp112
-rw-r--r--Source/JavaScriptCore/API/JSStringRef.h145
-rw-r--r--Source/JavaScriptCore/API/JSStringRefBSTR.cpp42
-rw-r--r--Source/JavaScriptCore/API/JSStringRefBSTR.h62
-rw-r--r--Source/JavaScriptCore/API/JSStringRefCF.cpp57
-rw-r--r--Source/JavaScriptCore/API/JSStringRefCF.h60
-rw-r--r--Source/JavaScriptCore/API/JSValueRef.cpp334
-rw-r--r--Source/JavaScriptCore/API/JSValueRef.h301
-rw-r--r--Source/JavaScriptCore/API/JSWeakObjectMapRefInternal.h68
-rw-r--r--Source/JavaScriptCore/API/JSWeakObjectMapRefPrivate.cpp83
-rw-r--r--Source/JavaScriptCore/API/JSWeakObjectMapRefPrivate.h95
-rw-r--r--Source/JavaScriptCore/API/JavaScript.h36
-rw-r--r--Source/JavaScriptCore/API/JavaScriptCore.h32
-rw-r--r--Source/JavaScriptCore/API/OpaqueJSString.cpp55
-rw-r--r--Source/JavaScriptCore/API/OpaqueJSString.h81
-rw-r--r--Source/JavaScriptCore/API/WebKitAvailability.h904
-rw-r--r--Source/JavaScriptCore/API/tests/JSNode.c196
-rw-r--r--Source/JavaScriptCore/API/tests/JSNode.h37
-rw-r--r--Source/JavaScriptCore/API/tests/JSNodeList.c123
-rw-r--r--Source/JavaScriptCore/API/tests/JSNodeList.h34
-rw-r--r--Source/JavaScriptCore/API/tests/Node.c85
-rw-r--r--Source/JavaScriptCore/API/tests/Node.h50
-rw-r--r--Source/JavaScriptCore/API/tests/NodeList.c81
-rw-r--r--Source/JavaScriptCore/API/tests/NodeList.h42
-rw-r--r--Source/JavaScriptCore/API/tests/minidom.c126
-rw-r--r--Source/JavaScriptCore/API/tests/minidom.html9
-rw-r--r--Source/JavaScriptCore/API/tests/minidom.js110
-rw-r--r--Source/JavaScriptCore/API/tests/testapi.c1458
-rw-r--r--Source/JavaScriptCore/API/tests/testapi.js251
52 files changed, 9134 insertions, 0 deletions
diff --git a/Source/JavaScriptCore/API/APICast.h b/Source/JavaScriptCore/API/APICast.h
new file mode 100644
index 0000000..4294d3d
--- /dev/null
+++ b/Source/JavaScriptCore/API/APICast.h
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2006 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 APICast_h
+#define APICast_h
+
+#include "JSAPIValueWrapper.h"
+#include "JSGlobalObject.h"
+#include "JSValue.h"
+#include <wtf/UnusedParam.h>
+
+namespace JSC {
+ class ExecState;
+ class PropertyNameArray;
+ class JSGlobalData;
+ class JSObject;
+ class JSValue;
+}
+
+typedef const struct OpaqueJSContextGroup* JSContextGroupRef;
+typedef const struct OpaqueJSContext* JSContextRef;
+typedef struct OpaqueJSContext* JSGlobalContextRef;
+typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;
+typedef const struct OpaqueJSValue* JSValueRef;
+typedef struct OpaqueJSValue* JSObjectRef;
+
+/* Opaque typing convenience methods */
+
+inline JSC::ExecState* toJS(JSContextRef c)
+{
+ ASSERT(c);
+ return reinterpret_cast<JSC::ExecState*>(const_cast<OpaqueJSContext*>(c));
+}
+
+inline JSC::ExecState* toJS(JSGlobalContextRef c)
+{
+ ASSERT(c);
+ return reinterpret_cast<JSC::ExecState*>(c);
+}
+
+inline JSC::JSValue toJS(JSC::ExecState* exec, JSValueRef v)
+{
+ ASSERT_UNUSED(exec, exec);
+ ASSERT(v);
+#if USE(JSVALUE32_64)
+ JSC::JSCell* jsCell = reinterpret_cast<JSC::JSCell*>(const_cast<OpaqueJSValue*>(v));
+ if (!jsCell)
+ return JSC::JSValue();
+ if (jsCell->isAPIValueWrapper())
+ return static_cast<JSC::JSAPIValueWrapper*>(jsCell)->value();
+ return jsCell;
+#else
+ return JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(const_cast<OpaqueJSValue*>(v)));
+#endif
+}
+
+inline JSC::JSValue toJSForGC(JSC::ExecState* exec, JSValueRef v)
+{
+ ASSERT_UNUSED(exec, exec);
+ ASSERT(v);
+#if USE(JSVALUE32_64)
+ JSC::JSCell* jsCell = reinterpret_cast<JSC::JSCell*>(const_cast<OpaqueJSValue*>(v));
+ if (!jsCell)
+ return JSC::JSValue();
+ return jsCell;
+#else
+ return JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(const_cast<OpaqueJSValue*>(v)));
+#endif
+}
+
+inline JSC::JSObject* toJS(JSObjectRef o)
+{
+ return reinterpret_cast<JSC::JSObject*>(o);
+}
+
+inline JSC::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a)
+{
+ return reinterpret_cast<JSC::PropertyNameArray*>(a);
+}
+
+inline JSC::JSGlobalData* toJS(JSContextGroupRef g)
+{
+ return reinterpret_cast<JSC::JSGlobalData*>(const_cast<OpaqueJSContextGroup*>(g));
+}
+
+inline JSValueRef toRef(JSC::ExecState* exec, JSC::JSValue v)
+{
+#if USE(JSVALUE32_64)
+ if (!v)
+ return 0;
+ if (!v.isCell())
+ return reinterpret_cast<JSValueRef>(JSC::jsAPIValueWrapper(exec, v).asCell());
+ return reinterpret_cast<JSValueRef>(v.asCell());
+#else
+ UNUSED_PARAM(exec);
+ return reinterpret_cast<JSValueRef>(JSC::JSValue::encode(v));
+#endif
+}
+
+inline JSObjectRef toRef(JSC::JSObject* o)
+{
+ return reinterpret_cast<JSObjectRef>(o);
+}
+
+inline JSObjectRef toRef(const JSC::JSObject* o)
+{
+ return reinterpret_cast<JSObjectRef>(const_cast<JSC::JSObject*>(o));
+}
+
+inline JSContextRef toRef(JSC::ExecState* e)
+{
+ return reinterpret_cast<JSContextRef>(e);
+}
+
+inline JSGlobalContextRef toGlobalRef(JSC::ExecState* e)
+{
+ ASSERT(e == e->lexicalGlobalObject()->globalExec());
+ return reinterpret_cast<JSGlobalContextRef>(e);
+}
+
+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/Source/JavaScriptCore/API/APIShims.h b/Source/JavaScriptCore/API/APIShims.h
new file mode 100644
index 0000000..0b49d70
--- /dev/null
+++ b/Source/JavaScriptCore/API/APIShims.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2009 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 APIShims_h
+#define APIShims_h
+
+#include "CallFrame.h"
+#include "GCActivityCallback.h"
+#include "JSLock.h"
+#include <wtf/WTFThreadData.h>
+
+namespace JSC {
+
+class APIEntryShimWithoutLock {
+protected:
+ APIEntryShimWithoutLock(JSGlobalData* globalData, bool registerThread)
+ : m_globalData(globalData)
+ , m_entryIdentifierTable(wtfThreadData().setCurrentIdentifierTable(globalData->identifierTable))
+ {
+ if (registerThread)
+ globalData->heap.registerThread();
+ m_globalData->heap.activityCallback()->synchronize();
+ m_globalData->timeoutChecker.start();
+ }
+
+ ~APIEntryShimWithoutLock()
+ {
+ m_globalData->timeoutChecker.stop();
+ wtfThreadData().setCurrentIdentifierTable(m_entryIdentifierTable);
+ }
+
+private:
+ JSGlobalData* m_globalData;
+ IdentifierTable* m_entryIdentifierTable;
+};
+
+class APIEntryShim : public APIEntryShimWithoutLock {
+public:
+ // Normal API entry
+ APIEntryShim(ExecState* exec, bool registerThread = true)
+ : APIEntryShimWithoutLock(&exec->globalData(), registerThread)
+ , m_lock(exec)
+ {
+ }
+
+ // JSPropertyNameAccumulator only has a globalData.
+ APIEntryShim(JSGlobalData* globalData, bool registerThread = true)
+ : APIEntryShimWithoutLock(globalData, registerThread)
+ , m_lock(globalData->isSharedInstance() ? LockForReal : SilenceAssertionsOnly)
+ {
+ }
+
+private:
+ JSLock m_lock;
+};
+
+class APICallbackShim {
+public:
+ APICallbackShim(ExecState* exec)
+ : m_dropAllLocks(exec)
+ , m_globalData(&exec->globalData())
+ {
+ wtfThreadData().resetCurrentIdentifierTable();
+ }
+
+ ~APICallbackShim()
+ {
+ m_globalData->heap.activityCallback()->synchronize();
+ wtfThreadData().setCurrentIdentifierTable(m_globalData->identifierTable);
+ }
+
+private:
+ JSLock::DropAllLocks m_dropAllLocks;
+ JSGlobalData* m_globalData;
+};
+
+}
+
+#endif
diff --git a/Source/JavaScriptCore/API/JSBase.cpp b/Source/JavaScriptCore/API/JSBase.cpp
new file mode 100644
index 0000000..c5f1b15
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSBase.cpp
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2006, 2007 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 "JSBase.h"
+#include "JSBasePrivate.h"
+
+#include "APICast.h"
+#include "APIShims.h"
+#include "Completion.h"
+#include "OpaqueJSString.h"
+#include "SourceCode.h"
+#include <interpreter/CallFrame.h>
+#include <runtime/InitializeThreading.h>
+#include <runtime/Completion.h>
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSLock.h>
+#include <runtime/JSObject.h>
+#include <wtf/text/StringHash.h>
+
+using namespace JSC;
+
+JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSObject* jsThisObject = toJS(thisObject);
+
+ // evaluate sets "this" to the global object if it is NULL
+ JSGlobalObject* globalObject = exec->dynamicGlobalObject();
+ SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber);
+ Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), source, jsThisObject);
+
+ if (completion.complType() == Throw) {
+ if (exception)
+ *exception = toRef(exec, completion.value());
+ return 0;
+ }
+
+ if (completion.value())
+ return toRef(exec, completion.value());
+
+ // happens, for example, when the only statement is an empty (';') statement
+ return toRef(exec, jsUndefined());
+}
+
+bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ SourceCode source = makeSource(script->ustring(), sourceURL->ustring(), startingLineNumber);
+ Completion completion = checkSyntax(exec->dynamicGlobalObject()->globalExec(), source);
+ if (completion.complType() == Throw) {
+ if (exception)
+ *exception = toRef(exec, completion.value());
+ return false;
+ }
+
+ return true;
+}
+
+void JSGarbageCollect(JSContextRef ctx)
+{
+ // 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);
+ APIEntryShim entryShim(exec, false);
+
+ JSGlobalData& globalData = exec->globalData();
+ if (!globalData.heap.isBusy())
+ globalData.heap.collectAllGarbage();
+
+ // 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);
+ APIEntryShim entryShim(exec);
+ exec->globalData().heap.reportExtraMemoryCost(size);
+}
diff --git a/Source/JavaScriptCore/API/JSBase.h b/Source/JavaScriptCore/API/JSBase.h
new file mode 100644
index 0000000..2e16720
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSBase.h
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2006 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 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;
+
+/*! @typedef JSGlobalContextRef A global JavaScript execution context. A JSGlobalContext is a JSContext. */
+typedef struct OpaqueJSContext* JSGlobalContextRef;
+
+/*! @typedef JSStringRef A UTF16 character buffer. The fundamental string representation in JavaScript. */
+typedef struct OpaqueJSString* JSStringRef;
+
+/*! @typedef JSClassRef A JavaScript class. Used with JSObjectMake to construct objects with custom behavior. */
+typedef struct OpaqueJSClass* JSClassRef;
+
+/*! @typedef JSPropertyNameArrayRef An array of JavaScript property names. */
+typedef struct OpaqueJSPropertyNameArray* JSPropertyNameArrayRef;
+
+/*! @typedef JSPropertyNameAccumulatorRef An ordered set used to collect the names of a JavaScript object's properties. */
+typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;
+
+
+/* JavaScript data types */
+
+/*! @typedef JSValueRef A JavaScript value. The base type for all JavaScript values, and polymorphic functions on them. */
+typedef const struct OpaqueJSValue* JSValueRef;
+
+/*! @typedef JSObjectRef A JavaScript object. A JSObject is a JSValue. */
+typedef struct OpaqueJSValue* JSObjectRef;
+
+/* JavaScript symbol exports */
+
+#undef JS_EXPORT
+#if defined(JS_NO_EXPORT)
+ #define JS_EXPORT
+#elif defined(__GNUC__) && !defined(__CC_ARM) && !defined(__ARMCC__)
+ #define JS_EXPORT __attribute__((visibility("default")))
+#elif defined(WIN32) || defined(_WIN32) || defined(_WIN32_WCE)
+ #if defined(BUILDING_JavaScriptCore) || defined(BUILDING_WTF)
+ #define JS_EXPORT __declspec(dllexport)
+ #else
+ #define JS_EXPORT __declspec(dllimport)
+ #endif
+#else
+ #define JS_EXPORT
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Script Evaluation */
+
+/*!
+@function JSEvaluateScript
+@abstract Evaluates a string of JavaScript.
+@param ctx The execution context to use.
+@param script A JSString containing the script to evaluate.
+@param thisObject The object to use as "this," or NULL to use the global object as "this."
+@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
+@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
+@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 The JSValue that results from evaluating script, or NULL if an exception is thrown.
+*/
+JS_EXPORT JSValueRef JSEvaluateScript(JSContextRef ctx, JSStringRef script, JSObjectRef thisObject, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+
+/*!
+@function JSCheckScriptSyntax
+@abstract Checks for syntax errors in a string of JavaScript.
+@param ctx The execution context to use.
+@param script A JSString containing the script to check for syntax errors.
+@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
+@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
+@param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
+@result true if the script is syntactically correct, otherwise false.
+*/
+JS_EXPORT bool JSCheckScriptSyntax(JSContextRef ctx, JSStringRef script, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+
+/*!
+@function JSGarbageCollect
+@abstract Performs a JavaScript garbage collection.
+@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.
+
+ During JavaScript execution, you are not required to call this function; the
+ 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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSBase_h */
diff --git a/Source/JavaScriptCore/API/JSBasePrivate.h b/Source/JavaScriptCore/API/JSBasePrivate.h
new file mode 100644
index 0000000..befa316
--- /dev/null
+++ b/Source/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_IN_WEBKIT_VERSION_4_0;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSBasePrivate_h */
diff --git a/Source/JavaScriptCore/API/JSCallbackConstructor.cpp b/Source/JavaScriptCore/API/JSCallbackConstructor.cpp
new file mode 100644
index 0000000..66c6b88
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSCallbackConstructor.cpp
@@ -0,0 +1,89 @@
+/*
+ * 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
+ * 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 "JSCallbackConstructor.h"
+
+#include "APIShims.h"
+#include "APICast.h"
+#include <runtime/Error.h>
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSLock.h>
+#include <runtime/ObjectPrototype.h>
+#include <wtf/Vector.h>
+
+namespace JSC {
+
+const ClassInfo JSCallbackConstructor::info = { "CallbackConstructor", 0, 0, 0 };
+
+JSCallbackConstructor::JSCallbackConstructor(JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure, JSClassRef jsClass, JSObjectCallAsConstructorCallback callback)
+ : JSObjectWithGlobalObject(globalObject, structure)
+ , m_class(jsClass)
+ , m_callback(callback)
+{
+ if (m_class)
+ JSClassRetain(jsClass);
+}
+
+JSCallbackConstructor::~JSCallbackConstructor()
+{
+ if (m_class)
+ JSClassRelease(m_class);
+}
+
+static EncodedJSValue JSC_HOST_CALL constructJSCallback(ExecState* exec)
+{
+ JSObject* constructor = exec->callee();
+ JSContextRef ctx = toRef(exec);
+ JSObjectRef constructorRef = toRef(constructor);
+
+ JSObjectCallAsConstructorCallback callback = static_cast<JSCallbackConstructor*>(constructor)->callback();
+ if (callback) {
+ int argumentCount = static_cast<int>(exec->argumentCount());
+ Vector<JSValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(exec, exec->argument(i));
+
+ JSValueRef exception = 0;
+ JSObjectRef result;
+ {
+ APICallbackShim callbackShim(exec);
+ result = callback(ctx, constructorRef, argumentCount, arguments.data(), &exception);
+ }
+ if (exception)
+ throwError(exec, toJS(exec, exception));
+ return JSValue::encode(toJS(result));
+ }
+
+ return JSValue::encode(toJS(JSObjectMake(ctx, static_cast<JSCallbackConstructor*>(constructor)->classRef(), 0)));
+}
+
+ConstructType JSCallbackConstructor::getConstructData(ConstructData& constructData)
+{
+ constructData.native.function = constructJSCallback;
+ return ConstructTypeHost;
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/API/JSCallbackConstructor.h b/Source/JavaScriptCore/API/JSCallbackConstructor.h
new file mode 100644
index 0000000..a6d64cc
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSCallbackConstructor.h
@@ -0,0 +1,60 @@
+/*
+ * 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
+ * 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 JSCallbackConstructor_h
+#define JSCallbackConstructor_h
+
+#include "JSObjectRef.h"
+#include <runtime/JSObjectWithGlobalObject.h>
+
+namespace JSC {
+
+class JSCallbackConstructor : public JSObjectWithGlobalObject {
+public:
+ JSCallbackConstructor(JSGlobalObject*, NonNullPassRefPtr<Structure>, JSClassRef, JSObjectCallAsConstructorCallback);
+ virtual ~JSCallbackConstructor();
+ JSClassRef classRef() const { return m_class; }
+ JSObjectCallAsConstructorCallback callback() const { return m_callback; }
+ static const ClassInfo info;
+
+ static PassRefPtr<Structure> createStructure(JSValue proto)
+ {
+ return Structure::create(proto, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount);
+ }
+
+protected:
+ static const unsigned StructureFlags = ImplementsHasInstance | JSObject::StructureFlags;
+
+private:
+ virtual ConstructType getConstructData(ConstructData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ JSClassRef m_class;
+ JSObjectCallAsConstructorCallback m_callback;
+};
+
+} // namespace JSC
+
+#endif // JSCallbackConstructor_h
diff --git a/Source/JavaScriptCore/API/JSCallbackFunction.cpp b/Source/JavaScriptCore/API/JSCallbackFunction.cpp
new file mode 100644
index 0000000..c488aa6
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSCallbackFunction.cpp
@@ -0,0 +1,80 @@
+/*
+ * 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
+ * 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 "JSCallbackFunction.h"
+
+#include "APIShims.h"
+#include "APICast.h"
+#include "CodeBlock.h"
+#include "ExceptionHelpers.h"
+#include "JSFunction.h"
+#include "FunctionPrototype.h"
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSLock.h>
+#include <wtf/Vector.h>
+
+namespace JSC {
+
+ASSERT_CLASS_FITS_IN_CELL(JSCallbackFunction);
+
+const ClassInfo JSCallbackFunction::info = { "CallbackFunction", &InternalFunction::info, 0, 0 };
+
+JSCallbackFunction::JSCallbackFunction(ExecState* exec, JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback callback, const Identifier& name)
+ : InternalFunction(&exec->globalData(), globalObject, globalObject->callbackFunctionStructure(), name)
+ , m_callback(callback)
+{
+}
+
+EncodedJSValue JSCallbackFunction::call(ExecState* exec)
+{
+ JSContextRef execRef = toRef(exec);
+ JSObjectRef functionRef = toRef(exec->callee());
+ JSObjectRef thisObjRef = toRef(exec->hostThisValue().toThisObject(exec));
+
+ int argumentCount = static_cast<int>(exec->argumentCount());
+ Vector<JSValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(exec, exec->argument(i));
+
+ JSValueRef exception = 0;
+ JSValueRef result;
+ {
+ APICallbackShim callbackShim(exec);
+ result = static_cast<JSCallbackFunction*>(toJS(functionRef))->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception);
+ }
+ if (exception)
+ throwError(exec, toJS(exec, exception));
+
+ return JSValue::encode(toJS(exec, result));
+}
+
+CallType JSCallbackFunction::getCallData(CallData& callData)
+{
+ callData.native.function = call;
+ return CallTypeHost;
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/API/JSCallbackFunction.h b/Source/JavaScriptCore/API/JSCallbackFunction.h
new file mode 100644
index 0000000..b119b97
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSCallbackFunction.h
@@ -0,0 +1,58 @@
+/*
+ * 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
+ * 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 JSCallbackFunction_h
+#define JSCallbackFunction_h
+
+#include "InternalFunction.h"
+#include "JSObjectRef.h"
+
+namespace JSC {
+
+class JSCallbackFunction : public InternalFunction {
+public:
+ JSCallbackFunction(ExecState*, JSGlobalObject*, JSObjectCallAsFunctionCallback, const Identifier& name);
+
+ static const ClassInfo info;
+
+ // InternalFunction mish-mashes constructor and function behavior -- we should
+ // refactor the code so this override isn't necessary
+ static PassRefPtr<Structure> createStructure(JSValue proto)
+ {
+ return Structure::create(proto, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount);
+ }
+
+private:
+ virtual CallType getCallData(CallData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ static EncodedJSValue JSC_HOST_CALL call(ExecState*);
+
+ JSObjectCallAsFunctionCallback m_callback;
+};
+
+} // namespace JSC
+
+#endif // JSCallbackFunction_h
diff --git a/Source/JavaScriptCore/API/JSCallbackObject.cpp b/Source/JavaScriptCore/API/JSCallbackObject.cpp
new file mode 100644
index 0000000..abd2adc
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSCallbackObject.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
+ *
+ * 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 "JSCallbackObject.h"
+
+#include "Collector.h"
+#include <wtf/text/StringHash.h>
+
+namespace JSC {
+
+ASSERT_CLASS_FITS_IN_CELL(JSCallbackObject<JSObjectWithGlobalObject>);
+ASSERT_CLASS_FITS_IN_CELL(JSCallbackObject<JSGlobalObject>);
+
+// Define the two types of JSCallbackObjects we support.
+template <> const ClassInfo JSCallbackObject<JSObjectWithGlobalObject>::info = { "CallbackObject", 0, 0, 0 };
+template <> const ClassInfo JSCallbackObject<JSGlobalObject>::info = { "CallbackGlobalObject", 0, 0, 0 };
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/API/JSCallbackObject.h b/Source/JavaScriptCore/API/JSCallbackObject.h
new file mode 100644
index 0000000..83442b2
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSCallbackObject.h
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
+ *
+ * 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 JSCallbackObject_h
+#define JSCallbackObject_h
+
+#include "JSObjectRef.h"
+#include "JSValueRef.h"
+#include "JSObject.h"
+#include <wtf/PassOwnPtr.h>
+
+namespace JSC {
+
+struct JSCallbackObjectData {
+ JSCallbackObjectData(void* privateData, JSClassRef jsClass)
+ : privateData(privateData)
+ , jsClass(jsClass)
+ {
+ JSClassRetain(jsClass);
+ }
+
+ ~JSCallbackObjectData()
+ {
+ JSClassRelease(jsClass);
+ }
+
+ JSValue getPrivateProperty(const Identifier& propertyName) const
+ {
+ if (!m_privateProperties)
+ return JSValue();
+ return m_privateProperties->getPrivateProperty(propertyName);
+ }
+
+ void setPrivateProperty(const Identifier& propertyName, JSValue value)
+ {
+ if (!m_privateProperties)
+ m_privateProperties = adoptPtr(new JSPrivatePropertyMap);
+ m_privateProperties->setPrivateProperty(propertyName, value);
+ }
+
+ void deletePrivateProperty(const Identifier& propertyName)
+ {
+ if (!m_privateProperties)
+ return;
+ m_privateProperties->deletePrivateProperty(propertyName);
+ }
+
+ void markChildren(MarkStack& markStack)
+ {
+ if (!m_privateProperties)
+ return;
+ m_privateProperties->markChildren(markStack);
+ }
+
+ void* privateData;
+ JSClassRef jsClass;
+ struct JSPrivatePropertyMap {
+ JSValue getPrivateProperty(const Identifier& propertyName) const
+ {
+ PrivatePropertyMap::const_iterator location = m_propertyMap.find(propertyName.impl());
+ if (location == m_propertyMap.end())
+ return JSValue();
+ return location->second;
+ }
+
+ void setPrivateProperty(const Identifier& propertyName, JSValue value)
+ {
+ m_propertyMap.set(propertyName.impl(), value);
+ }
+
+ void deletePrivateProperty(const Identifier& propertyName)
+ {
+ m_propertyMap.remove(propertyName.impl());
+ }
+
+ void markChildren(MarkStack& markStack)
+ {
+ for (PrivatePropertyMap::iterator ptr = m_propertyMap.begin(); ptr != m_propertyMap.end(); ++ptr) {
+ if (ptr->second)
+ markStack.append(ptr->second);
+ }
+ }
+
+ private:
+ typedef HashMap<RefPtr<StringImpl>, JSValue, IdentifierRepHash> PrivatePropertyMap;
+ PrivatePropertyMap m_propertyMap;
+ };
+ OwnPtr<JSPrivatePropertyMap> m_privateProperties;
+};
+
+
+template <class Base>
+class JSCallbackObject : public Base {
+public:
+ JSCallbackObject(ExecState*, JSGlobalObject*, NonNullPassRefPtr<Structure>, JSClassRef, void* data);
+ JSCallbackObject(JSClassRef, NonNullPassRefPtr<Structure>);
+ 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<Structure> createStructure(JSValue proto)
+ {
+ return Structure::create(proto, TypeInfo(ObjectType, StructureFlags), Base::AnonymousSlotCount);
+ }
+
+ JSValue getPrivateProperty(const Identifier& propertyName) const
+ {
+ return m_callbackObjectData->getPrivateProperty(propertyName);
+ }
+
+ void setPrivateProperty(const Identifier& propertyName, JSValue value)
+ {
+ m_callbackObjectData->setPrivateProperty(propertyName, value);
+ }
+
+ void deletePrivateProperty(const Identifier& propertyName)
+ {
+ m_callbackObjectData->deletePrivateProperty(propertyName);
+ }
+
+protected:
+ static const unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesHasInstance | OverridesMarkChildren | OverridesGetPropertyNames | Base::StructureFlags;
+
+private:
+ virtual UString className() const;
+
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
+ virtual bool getOwnPropertySlot(ExecState*, unsigned, PropertySlot&);
+ virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
+
+ virtual void put(ExecState*, const Identifier&, JSValue, PutPropertySlot&);
+
+ virtual bool deleteProperty(ExecState*, const Identifier&);
+ virtual bool deleteProperty(ExecState*, unsigned);
+
+ virtual bool hasInstance(ExecState* exec, JSValue value, JSValue proto);
+
+ virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
+
+ virtual double toNumber(ExecState*) const;
+ virtual UString toString(ExecState*) const;
+
+ virtual ConstructType getConstructData(ConstructData&);
+ virtual CallType getCallData(CallData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ virtual void markChildren(MarkStack& markStack)
+ {
+ Base::markChildren(markStack);
+ m_callbackObjectData->markChildren(markStack);
+ }
+
+ void init(ExecState*);
+
+ static JSCallbackObject* asCallbackObject(JSValue);
+
+ static EncodedJSValue JSC_HOST_CALL call(ExecState*);
+ static EncodedJSValue JSC_HOST_CALL construct(ExecState*);
+
+ static JSValue staticValueGetter(ExecState*, JSValue, const Identifier&);
+ static JSValue staticFunctionGetter(ExecState*, JSValue, const Identifier&);
+ static JSValue callbackGetter(ExecState*, JSValue, const Identifier&);
+
+ OwnPtr<JSCallbackObjectData> m_callbackObjectData;
+};
+
+} // namespace JSC
+
+// include the actual template class implementation
+#include "JSCallbackObjectFunctions.h"
+
+#endif // JSCallbackObject_h
diff --git a/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h b/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
new file mode 100644
index 0000000..de5d842
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSCallbackObjectFunctions.h
@@ -0,0 +1,607 @@
+/*
+ * 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
+ * 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 "APIShims.h"
+#include "APICast.h"
+#include "Error.h"
+#include "ExceptionHelpers.h"
+#include "JSCallbackFunction.h"
+#include "JSClassRef.h"
+#include "JSFunction.h"
+#include "JSGlobalObject.h"
+#include "JSLock.h"
+#include "JSObjectRef.h"
+#include "JSString.h"
+#include "JSStringRef.h"
+#include "OpaqueJSString.h"
+#include "PropertyNameArray.h"
+#include <wtf/Vector.h>
+
+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, JSGlobalObject* globalObject, NonNullPassRefPtr<Structure> structure, JSClassRef jsClass, void* data)
+ : Base(globalObject, structure)
+ , m_callbackObjectData(adoptPtr(new JSCallbackObjectData(data, jsClass)))
+{
+ init(exec);
+}
+
+// Global object constructor.
+// FIXME: Move this into a separate JSGlobalCallbackObject class derived from this one.
+template <class Base>
+JSCallbackObject<Base>::JSCallbackObject(JSClassRef jsClass, NonNullPassRefPtr<Structure> structure)
+ : Base(structure)
+ , m_callbackObjectData(adoptPtr(new JSCallbackObjectData(0, jsClass)))
+{
+ ASSERT(Base::isGlobalObject());
+ init(static_cast<JSGlobalObject*>(this)->globalExec());
+}
+
+template <class Base>
+void JSCallbackObject<Base>::init(ExecState* exec)
+{
+ ASSERT(exec);
+
+ Vector<JSObjectInitializeCallback, 16> initRoutines;
+ JSClassRef jsClass = classRef();
+ do {
+ if (JSObjectInitializeCallback initialize = jsClass->initialize)
+ initRoutines.append(initialize);
+ } while ((jsClass = jsClass->parentClass));
+
+ // initialize from base to derived
+ for (int i = static_cast<int>(initRoutines.size()) - 1; i >= 0; i--) {
+ APICallbackShim callbackShim(exec);
+ JSObjectInitializeCallback initialize = initRoutines[i];
+ initialize(toRef(exec), toRef(this));
+ }
+}
+
+template <class Base>
+JSCallbackObject<Base>::~JSCallbackObject()
+{
+ JSObjectRef thisRef = toRef(this);
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (JSObjectFinalizeCallback finalize = jsClass->finalize)
+ finalize(thisRef);
+}
+
+template <class Base>
+UString JSCallbackObject<Base>::className() const
+{
+ UString thisClassName = classRef()->className();
+ if (!thisClassName.isEmpty())
+ return thisClassName;
+
+ return Base::className();
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ JSContextRef ctx = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+ RefPtr<OpaqueJSString> propertyNameRef;
+
+ 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) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ APICallbackShim callbackShim(exec);
+ if (hasProperty(ctx, thisRef, propertyNameRef.get())) {
+ slot.setCustom(this, callbackGetter);
+ return true;
+ }
+ } else if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSValueRef exception = 0;
+ JSValueRef value;
+ {
+ APICallbackShim callbackShim(exec);
+ value = getProperty(ctx, thisRef, propertyNameRef.get(), &exception);
+ }
+ if (exception) {
+ throwError(exec, toJS(exec, exception));
+ slot.setValue(jsUndefined());
+ return true;
+ }
+ if (value) {
+ slot.setValue(toJS(exec, value));
+ return true;
+ }
+ }
+
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (staticValues->contains(propertyName.impl())) {
+ slot.setCustom(this, staticValueGetter);
+ return true;
+ }
+ }
+
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (staticFunctions->contains(propertyName.impl())) {
+ slot.setCustom(this, staticFunctionGetter);
+ return true;
+ }
+ }
+ }
+
+ return Base::getOwnPropertySlot(exec, propertyName, slot);
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
+{
+ return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
+{
+ PropertySlot slot;
+ if (getOwnPropertySlot(exec, propertyName, slot)) {
+ // Ideally we should return an access descriptor, but returning a value descriptor is better than nothing.
+ JSValue value = slot.getValue(exec, propertyName);
+ if (!exec->hadException())
+ descriptor.setValue(value);
+ // We don't know whether the property is configurable, but assume it is.
+ descriptor.setConfigurable(true);
+ // We don't know whether the property is enumerable (we could call getOwnPropertyNames() to find out), but assume it isn't.
+ descriptor.setEnumerable(false);
+ return true;
+ }
+
+ return Base::getOwnPropertyDescriptor(exec, propertyName, descriptor);
+}
+
+template <class Base>
+void JSCallbackObject<Base>::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
+{
+ JSContextRef ctx = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+ RefPtr<OpaqueJSString> propertyNameRef;
+ JSValueRef valueRef = toRef(exec, value);
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectSetPropertyCallback setProperty = jsClass->setProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSValueRef exception = 0;
+ bool result;
+ {
+ APICallbackShim callbackShim(exec);
+ result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
+ }
+ if (exception)
+ throwError(exec, toJS(exec, exception));
+ if (result || exception)
+ return;
+ }
+
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (StaticValueEntry* entry = staticValues->get(propertyName.impl())) {
+ if (entry->attributes & kJSPropertyAttributeReadOnly)
+ return;
+ if (JSObjectSetPropertyCallback setProperty = entry->setProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSValueRef exception = 0;
+ bool result;
+ {
+ APICallbackShim callbackShim(exec);
+ result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
+ }
+ if (exception)
+ throwError(exec, toJS(exec, exception));
+ if (result || exception)
+ return;
+ } else
+ throwError(exec, createReferenceError(exec, "Attempt to set a property that is not settable."));
+ }
+ }
+
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.impl())) {
+ if (entry->attributes & kJSPropertyAttributeReadOnly)
+ return;
+ JSCallbackObject<Base>::putDirect(propertyName, value); // put as override property
+ return;
+ }
+ }
+ }
+
+ return Base::put(exec, propertyName, value, slot);
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, const Identifier& propertyName)
+{
+ JSContextRef ctx = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+ RefPtr<OpaqueJSString> propertyNameRef;
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSValueRef exception = 0;
+ bool result;
+ {
+ APICallbackShim callbackShim(exec);
+ result = deleteProperty(ctx, thisRef, propertyNameRef.get(), &exception);
+ }
+ if (exception)
+ throwError(exec, toJS(exec, exception));
+ if (result || exception)
+ return true;
+ }
+
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (StaticValueEntry* entry = staticValues->get(propertyName.impl())) {
+ if (entry->attributes & kJSPropertyAttributeDontDelete)
+ return false;
+ return true;
+ }
+ }
+
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.impl())) {
+ if (entry->attributes & kJSPropertyAttributeDontDelete)
+ return false;
+ return true;
+ }
+ }
+ }
+
+ return Base::deleteProperty(exec, propertyName);
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::deleteProperty(ExecState* exec, unsigned propertyName)
+{
+ return deleteProperty(exec, Identifier::from(exec, propertyName));
+}
+
+template <class Base>
+ConstructType JSCallbackObject<Base>::getConstructData(ConstructData& constructData)
+{
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (jsClass->callAsConstructor) {
+ constructData.native.function = construct;
+ return ConstructTypeHost;
+ }
+ }
+ return ConstructTypeNone;
+}
+
+template <class Base>
+EncodedJSValue JSCallbackObject<Base>::construct(ExecState* exec)
+{
+ JSObject* constructor = exec->callee();
+ JSContextRef execRef = toRef(exec);
+ JSObjectRef constructorRef = toRef(constructor);
+
+ for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {
+ int argumentCount = static_cast<int>(exec->argumentCount());
+ Vector<JSValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(exec, exec->argument(i));
+ JSValueRef exception = 0;
+ JSObject* result;
+ {
+ APICallbackShim callbackShim(exec);
+ result = toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), &exception));
+ }
+ if (exception)
+ throwError(exec, toJS(exec, exception));
+ return JSValue::encode(result);
+ }
+ }
+
+ ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here
+ return JSValue::encode(JSValue());
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::hasInstance(ExecState* exec, JSValue value, JSValue)
+{
+ JSContextRef execRef = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectHasInstanceCallback hasInstance = jsClass->hasInstance) {
+ JSValueRef valueRef = toRef(exec, value);
+ JSValueRef exception = 0;
+ bool result;
+ {
+ APICallbackShim callbackShim(exec);
+ result = hasInstance(execRef, thisRef, valueRef, &exception);
+ }
+ if (exception)
+ throwError(exec, toJS(exec, exception));
+ return result;
+ }
+ }
+ return false;
+}
+
+template <class Base>
+CallType JSCallbackObject<Base>::getCallData(CallData& callData)
+{
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (jsClass->callAsFunction) {
+ callData.native.function = call;
+ return CallTypeHost;
+ }
+ }
+ return CallTypeNone;
+}
+
+template <class Base>
+EncodedJSValue JSCallbackObject<Base>::call(ExecState* exec)
+{
+ JSContextRef execRef = toRef(exec);
+ JSObjectRef functionRef = toRef(exec->callee());
+ JSObjectRef thisObjRef = toRef(exec->hostThisValue().toThisObject(exec));
+
+ for (JSClassRef jsClass = static_cast<JSCallbackObject<Base>*>(toJS(functionRef))->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) {
+ int argumentCount = static_cast<int>(exec->argumentCount());
+ Vector<JSValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(exec, exec->argument(i));
+ JSValueRef exception = 0;
+ JSValue result;
+ {
+ APICallbackShim callbackShim(exec);
+ result = toJS(exec, callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception));
+ }
+ if (exception)
+ throwError(exec, toJS(exec, exception));
+ return JSValue::encode(result);
+ }
+ }
+
+ ASSERT_NOT_REACHED(); // getCallData should prevent us from reaching here
+ return JSValue::encode(JSValue());
+}
+
+template <class Base>
+void JSCallbackObject<Base>::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
+{
+ JSContextRef execRef = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (JSObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames) {
+ APICallbackShim callbackShim(exec);
+ getPropertyNames(execRef, thisRef, toRef(&propertyNames));
+ }
+
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ typedef OpaqueJSClassStaticValuesTable::const_iterator iterator;
+ iterator end = staticValues->end();
+ for (iterator it = staticValues->begin(); it != end; ++it) {
+ StringImpl* name = it->first.get();
+ StaticValueEntry* entry = it->second;
+ if (entry->getProperty && (!(entry->attributes & kJSPropertyAttributeDontEnum) || (mode == IncludeDontEnumProperties)))
+ propertyNames.add(Identifier(exec, name));
+ }
+ }
+
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ typedef OpaqueJSClassStaticFunctionsTable::const_iterator iterator;
+ iterator end = staticFunctions->end();
+ for (iterator it = staticFunctions->begin(); it != end; ++it) {
+ StringImpl* name = it->first.get();
+ StaticFunctionEntry* entry = it->second;
+ if (!(entry->attributes & kJSPropertyAttributeDontEnum) || (mode == IncludeDontEnumProperties))
+ propertyNames.add(Identifier(exec, name));
+ }
+ }
+ }
+
+ Base::getOwnPropertyNames(exec, propertyNames, mode);
+}
+
+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 = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
+ JSValueRef exception = 0;
+ JSValueRef value;
+ {
+ APICallbackShim callbackShim(exec);
+ value = convertToType(ctx, thisRef, kJSTypeNumber, &exception);
+ }
+ if (exception) {
+ throwError(exec, toJS(exec, exception));
+ return 0;
+ }
+
+ double dValue;
+ if (value)
+ return toJS(exec, value).getNumber(dValue) ? dValue : NaN;
+ }
+
+ return Base::toNumber(exec);
+}
+
+template <class Base>
+UString JSCallbackObject<Base>::toString(ExecState* exec) const
+{
+ JSContextRef ctx = toRef(exec);
+ JSObjectRef thisRef = toRef(this);
+
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (JSObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
+ JSValueRef exception = 0;
+ JSValueRef value;
+ {
+ APICallbackShim callbackShim(exec);
+ value = convertToType(ctx, thisRef, kJSTypeString, &exception);
+ }
+ if (exception) {
+ throwError(exec, toJS(exec, exception));
+ return "";
+ }
+ if (value)
+ return toJS(exec, value).getString(exec);
+ }
+
+ return Base::toString(exec);
+}
+
+template <class Base>
+void JSCallbackObject<Base>::setPrivate(void* data)
+{
+ m_callbackObjectData->privateData = data;
+}
+
+template <class Base>
+void* JSCallbackObject<Base>::getPrivate()
+{
+ return m_callbackObjectData->privateData;
+}
+
+template <class Base>
+bool JSCallbackObject<Base>::inherits(JSClassRef c) const
+{
+ for (JSClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (jsClass == c)
+ return true;
+
+ return false;
+}
+
+template <class Base>
+JSValue JSCallbackObject<Base>::staticValueGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
+{
+ JSCallbackObject* thisObj = asCallbackObject(slotBase);
+
+ JSObjectRef thisRef = toRef(thisObj);
+ RefPtr<OpaqueJSString> propertyNameRef;
+
+ for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (OpaqueJSClassStaticValuesTable* staticValues = jsClass->staticValues(exec))
+ if (StaticValueEntry* entry = staticValues->get(propertyName.impl()))
+ if (JSObjectGetPropertyCallback getProperty = entry->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSValueRef exception = 0;
+ JSValueRef value;
+ {
+ APICallbackShim callbackShim(exec);
+ value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
+ }
+ if (exception) {
+ throwError(exec, toJS(exec, exception));
+ return jsUndefined();
+ }
+ if (value)
+ return toJS(exec, value);
+ }
+
+ return throwError(exec, createReferenceError(exec, "Static value property defined with NULL getProperty callback."));
+}
+
+template <class Base>
+JSValue JSCallbackObject<Base>::staticFunctionGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
+{
+ JSCallbackObject* thisObj = asCallbackObject(slotBase);
+
+ // Check for cached or override property.
+ PropertySlot slot2(thisObj);
+ if (thisObj->Base::getOwnPropertySlot(exec, propertyName, slot2))
+ return slot2.getValue(exec, propertyName);
+
+ for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (OpaqueJSClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.impl())) {
+ if (JSObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
+
+ JSObject* o = new (exec) JSCallbackFunction(exec, asGlobalObject(thisObj->getAnonymousValue(0)), callAsFunction, propertyName);
+ thisObj->putDirect(propertyName, o, entry->attributes);
+ return o;
+ }
+ }
+ }
+ }
+
+ return throwError(exec, createReferenceError(exec, "Static function property defined with NULL callAsFunction callback."));
+}
+
+template <class Base>
+JSValue JSCallbackObject<Base>::callbackGetter(ExecState* exec, JSValue slotBase, const Identifier& propertyName)
+{
+ JSCallbackObject* thisObj = asCallbackObject(slotBase);
+
+ JSObjectRef thisRef = toRef(thisObj);
+ RefPtr<OpaqueJSString> propertyNameRef;
+
+ for (JSClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (JSObjectGetPropertyCallback getProperty = jsClass->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueJSString::create(propertyName.ustring());
+ JSValueRef exception = 0;
+ JSValueRef value;
+ {
+ APICallbackShim callbackShim(exec);
+ value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
+ }
+ if (exception) {
+ throwError(exec, toJS(exec, exception));
+ return jsUndefined();
+ }
+ if (value)
+ return toJS(exec, value);
+ }
+
+ return throwError(exec, createReferenceError(exec, "hasProperty callback returned true for a property that doesn't exist."));
+}
+
+} // namespace JSC
diff --git a/Source/JavaScriptCore/API/JSClassRef.cpp b/Source/JavaScriptCore/API/JSClassRef.cpp
new file mode 100644
index 0000000..decf493
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSClassRef.cpp
@@ -0,0 +1,266 @@
+/*
+ * Copyright (C) 2006, 2007 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 "JSClassRef.h"
+
+#include "APICast.h"
+#include "JSCallbackObject.h"
+#include "JSObjectRef.h"
+#include <runtime/InitializeThreading.h>
+#include <runtime/JSGlobalObject.h>
+#include <runtime/ObjectPrototype.h>
+#include <runtime/Identifier.h>
+#include <wtf/text/StringHash.h>
+#include <wtf/unicode/UTF8.h>
+
+using namespace std;
+using namespace JSC;
+using namespace WTF::Unicode;
+
+const JSClassDefinition kJSClassDefinitionEmpty = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+static inline UString tryCreateStringFromUTF8(const char* string)
+{
+ if (!string)
+ return UString();
+
+ size_t length = strlen(string);
+ Vector<UChar, 1024> buffer(length);
+ UChar* p = buffer.data();
+ if (conversionOK != convertUTF8ToUTF16(&string, string + length, &p, p + length))
+ return UString();
+
+ return UString(buffer.data(), p - buffer.data());
+}
+
+OpaqueJSClass::OpaqueJSClass(const JSClassDefinition* definition, OpaqueJSClass* protoClass)
+ : parentClass(definition->parentClass)
+ , prototypeClass(0)
+ , initialize(definition->initialize)
+ , finalize(definition->finalize)
+ , hasProperty(definition->hasProperty)
+ , getProperty(definition->getProperty)
+ , setProperty(definition->setProperty)
+ , deleteProperty(definition->deleteProperty)
+ , getPropertyNames(definition->getPropertyNames)
+ , callAsFunction(definition->callAsFunction)
+ , callAsConstructor(definition->callAsConstructor)
+ , hasInstance(definition->hasInstance)
+ , convertToType(definition->convertToType)
+ , m_className(tryCreateStringFromUTF8(definition->className))
+ , m_staticValues(0)
+ , m_staticFunctions(0)
+{
+ initializeThreading();
+
+ if (const JSStaticValue* staticValue = definition->staticValues) {
+ m_staticValues = new OpaqueJSClassStaticValuesTable();
+ while (staticValue->name) {
+ UString valueName = tryCreateStringFromUTF8(staticValue->name);
+ if (!valueName.isNull()) {
+ // Use a local variable here to sidestep an RVCT compiler bug.
+ StaticValueEntry* entry = new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes);
+ StringImpl* impl = valueName.impl();
+ impl->ref();
+ m_staticValues->add(impl, entry);
+ }
+ ++staticValue;
+ }
+ }
+
+ if (const JSStaticFunction* staticFunction = definition->staticFunctions) {
+ m_staticFunctions = new OpaqueJSClassStaticFunctionsTable();
+ while (staticFunction->name) {
+ UString functionName = tryCreateStringFromUTF8(staticFunction->name);
+ if (!functionName.isNull()) {
+ // Use a local variable here to sidestep an RVCT compiler bug.
+ StaticFunctionEntry* entry = new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes);
+ StringImpl* impl = functionName.impl();
+ impl->ref();
+ m_staticFunctions->add(impl, entry);
+ }
+ ++staticFunction;
+ }
+ }
+
+ if (protoClass)
+ prototypeClass = JSClassRetain(protoClass);
+}
+
+OpaqueJSClass::~OpaqueJSClass()
+{
+ // The empty string is shared across threads & is an identifier, in all other cases we should have done a deep copy in className(), below.
+ ASSERT(!m_className.length() || !m_className.impl()->isIdentifier());
+
+ if (m_staticValues) {
+ OpaqueJSClassStaticValuesTable::const_iterator end = m_staticValues->end();
+ for (OpaqueJSClassStaticValuesTable::const_iterator it = m_staticValues->begin(); it != end; ++it) {
+ ASSERT(!it->first->isIdentifier());
+ delete it->second;
+ }
+ delete m_staticValues;
+ }
+
+ if (m_staticFunctions) {
+ OpaqueJSClassStaticFunctionsTable::const_iterator end = m_staticFunctions->end();
+ for (OpaqueJSClassStaticFunctionsTable::const_iterator it = m_staticFunctions->begin(); it != end; ++it) {
+ ASSERT(!it->first->isIdentifier());
+ delete it->second;
+ }
+ delete m_staticFunctions;
+ }
+
+ if (prototypeClass)
+ JSClassRelease(prototypeClass);
+}
+
+PassRefPtr<OpaqueJSClass> OpaqueJSClass::createNoAutomaticPrototype(const JSClassDefinition* definition)
+{
+ return adoptRef(new OpaqueJSClass(definition, 0));
+}
+
+static void clearReferenceToPrototype(JSObjectRef prototype)
+{
+ OpaqueJSClassContextData* jsClassData = static_cast<OpaqueJSClassContextData*>(JSObjectGetPrivate(prototype));
+ ASSERT(jsClassData);
+ jsClassData->cachedPrototype.clear(toJS(prototype));
+}
+
+PassRefPtr<OpaqueJSClass> OpaqueJSClass::create(const JSClassDefinition* clientDefinition)
+{
+ JSClassDefinition definition = *clientDefinition; // Avoid modifying client copy.
+
+ JSClassDefinition protoDefinition = kJSClassDefinitionEmpty;
+ protoDefinition.finalize = clearReferenceToPrototype;
+ swap(definition.staticFunctions, protoDefinition.staticFunctions); // Move static functions to the prototype.
+
+ // 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));
+ return adoptRef(new OpaqueJSClass(&definition, protoClass.get()));
+}
+
+OpaqueJSClassContextData::OpaqueJSClassContextData(OpaqueJSClass* jsClass)
+ : m_class(jsClass)
+{
+ 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->isIdentifier());
+ // Use a local variable here to sidestep an RVCT compiler bug.
+ StaticValueEntry* entry = new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes);
+ staticValues->add(StringImpl::create(it->first->characters(), it->first->length()), entry);
+ }
+ } 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->isIdentifier());
+ // Use a local variable here to sidestep an RVCT compiler bug.
+ StaticFunctionEntry* entry = new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes);
+ staticFunctions->add(StringImpl::create(it->first->characters(), it->first->length()), entry);
+ }
+
+ } else
+ staticFunctions = 0;
+}
+
+OpaqueJSClassContextData::~OpaqueJSClassContextData()
+{
+ if (staticValues) {
+ deleteAllValues(*staticValues);
+ delete staticValues;
+ }
+
+ 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.characters(), m_className.length());
+}
+
+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;
+}
+
+/*!
+// Doc here in case we make this public. (Hopefully we won't.)
+@function
+ @abstract Returns the prototype that will be used when constructing an object with a given class.
+ @param ctx The execution context to use.
+ @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(ExecState* exec)
+{
+ /* Class (C++) and prototype (JS) inheritance are parallel, so:
+ * (C++) | (JS)
+ * ParentClass | ParentClassPrototype
+ * ^ | ^
+ * | | |
+ * DerivedClass | DerivedClassPrototype
+ */
+
+ if (!prototypeClass)
+ return 0;
+
+ OpaqueJSClassContextData& jsClassData = contextData(exec);
+
+ if (!jsClassData.cachedPrototype) {
+ // Recursive, but should be good enough for our purposes
+ jsClassData.cachedPrototype = new (exec) JSCallbackObject<JSObjectWithGlobalObject>(exec, exec->lexicalGlobalObject(), 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 jsClassData.cachedPrototype.get();
+}
diff --git a/Source/JavaScriptCore/API/JSClassRef.h b/Source/JavaScriptCore/API/JSClassRef.h
new file mode 100644
index 0000000..5062093
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSClassRef.h
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2006 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 JSClassRef_h
+#define JSClassRef_h
+
+#include "JSObjectRef.h"
+
+#include <runtime/JSObject.h>
+#include <runtime/Protect.h>
+#include <runtime/UString.h>
+#include <runtime/WeakGCPtr.h>
+#include <wtf/HashMap.h>
+
+struct StaticValueEntry : FastAllocBase {
+ StaticValueEntry(JSObjectGetPropertyCallback _getProperty, JSObjectSetPropertyCallback _setProperty, JSPropertyAttributes _attributes)
+ : getProperty(_getProperty), setProperty(_setProperty), attributes(_attributes)
+ {
+ }
+
+ JSObjectGetPropertyCallback getProperty;
+ JSObjectSetPropertyCallback setProperty;
+ JSPropertyAttributes attributes;
+};
+
+struct StaticFunctionEntry : FastAllocBase {
+ StaticFunctionEntry(JSObjectCallAsFunctionCallback _callAsFunction, JSPropertyAttributes _attributes)
+ : callAsFunction(_callAsFunction), attributes(_attributes)
+ {
+ }
+
+ JSObjectCallAsFunctionCallback callAsFunction;
+ JSPropertyAttributes attributes;
+};
+
+typedef HashMap<RefPtr<StringImpl>, StaticValueEntry*> OpaqueJSClassStaticValuesTable;
+typedef HashMap<RefPtr<StringImpl>, StaticFunctionEntry*> OpaqueJSClassStaticFunctionsTable;
+
+struct 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::WeakGCPtr<JSC::JSObject> cachedPrototype;
+};
+
+struct OpaqueJSClass : public ThreadSafeShared<OpaqueJSClass> {
+ static PassRefPtr<OpaqueJSClass> create(const JSClassDefinition*);
+ static PassRefPtr<OpaqueJSClass> createNoAutomaticPrototype(const JSClassDefinition*);
+ ~OpaqueJSClass();
+
+ JSC::UString className();
+ OpaqueJSClassStaticValuesTable* staticValues(JSC::ExecState*);
+ OpaqueJSClassStaticFunctionsTable* staticFunctions(JSC::ExecState*);
+ JSC::JSObject* prototype(JSC::ExecState*);
+
+ OpaqueJSClass* parentClass;
+ OpaqueJSClass* prototypeClass;
+
+ JSObjectInitializeCallback initialize;
+ JSObjectFinalizeCallback finalize;
+ JSObjectHasPropertyCallback hasProperty;
+ JSObjectGetPropertyCallback getProperty;
+ JSObjectSetPropertyCallback setProperty;
+ JSObjectDeletePropertyCallback deleteProperty;
+ JSObjectGetPropertyNamesCallback getPropertyNames;
+ JSObjectCallAsFunctionCallback callAsFunction;
+ JSObjectCallAsConstructorCallback callAsConstructor;
+ JSObjectHasInstanceCallback hasInstance;
+ JSObjectConvertToTypeCallback convertToType;
+
+private:
+ friend struct OpaqueJSClassContextData;
+
+ OpaqueJSClass();
+ OpaqueJSClass(const OpaqueJSClass&);
+ OpaqueJSClass(const JSClassDefinition*, OpaqueJSClass* protoClass);
+
+ 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/Source/JavaScriptCore/API/JSContextRef.cpp b/Source/JavaScriptCore/API/JSContextRef.cpp
new file mode 100644
index 0000000..ccab953
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSContextRef.cpp
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2006, 2007 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 "JSContextRef.h"
+#include "JSContextRefPrivate.h"
+
+#include "APICast.h"
+#include "InitializeThreading.h"
+#include "JSCallbackObject.h"
+#include "JSClassRef.h"
+#include "JSGlobalObject.h"
+#include "JSObject.h"
+#include <wtf/text/StringHash.h>
+
+#if OS(DARWIN)
+#include <mach-o/dyld.h>
+
+static const int32_t webkitFirstVersionWithConcurrentGlobalContexts = 0x2100500; // 528.5.0
+#endif
+
+using namespace JSC;
+
+JSContextGroupRef JSContextGroupCreate()
+{
+ initializeThreading();
+ return toRef(JSGlobalData::createContextGroup(ThreadStackTypeSmall).leakRef());
+}
+
+JSContextGroupRef JSContextGroupRetain(JSContextGroupRef group)
+{
+ toJS(group)->ref();
+ return group;
+}
+
+void JSContextGroupRelease(JSContextGroupRef group)
+{
+ toJS(group)->deref();
+}
+
+JSGlobalContextRef JSGlobalContextCreate(JSClassRef globalObjectClass)
+{
+ initializeThreading();
+#if OS(DARWIN)
+ // When running on Tiger or Leopard, or if the application was linked before JSGlobalContextCreate was changed
+ // to use a unique JSGlobalData, we use a shared one for compatibility.
+#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
+ if (NSVersionOfLinkTimeLibrary("JavaScriptCore") <= webkitFirstVersionWithConcurrentGlobalContexts) {
+#else
+ {
+#endif
+ JSLock lock(LockForReal);
+ return JSGlobalContextCreateInGroup(toRef(&JSGlobalData::sharedInstance()), globalObjectClass);
+ }
+#endif // OS(DARWIN)
+
+ return JSGlobalContextCreateInGroup(0, globalObjectClass);
+}
+
+JSGlobalContextRef JSGlobalContextCreateInGroup(JSContextGroupRef group, JSClassRef globalObjectClass)
+{
+ initializeThreading();
+
+ JSLock lock(LockForReal);
+ RefPtr<JSGlobalData> globalData = group ? PassRefPtr<JSGlobalData>(toJS(group)) : JSGlobalData::createContextGroup(ThreadStackTypeSmall);
+
+ APIEntryShim entryShim(globalData.get(), false);
+
+#if ENABLE(JSC_MULTIPLE_THREADS)
+ globalData->makeUsableFromMultipleThreads();
+#endif
+
+ if (!globalObjectClass) {
+ JSGlobalObject* globalObject = new (globalData.get()) JSGlobalObject;
+ return JSGlobalContextRetain(toGlobalRef(globalObject->globalExec()));
+ }
+
+ JSGlobalObject* globalObject = new (globalData.get()) JSCallbackObject<JSGlobalObject>(globalObjectClass, JSCallbackObject<JSGlobalObject>::createStructure(jsNull()));
+ ExecState* exec = globalObject->globalExec();
+ JSValue prototype = globalObjectClass->prototype(exec);
+ if (!prototype)
+ prototype = jsNull();
+ globalObject->resetPrototype(prototype);
+ return JSGlobalContextRetain(toGlobalRef(exec));
+}
+
+JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSGlobalData& globalData = exec->globalData();
+ gcProtect(exec->dynamicGlobalObject());
+ globalData.ref();
+ return ctx;
+}
+
+void JSGlobalContextRelease(JSGlobalContextRef ctx)
+{
+ ExecState* exec = toJS(ctx);
+ JSLock lock(exec);
+
+ JSGlobalData& globalData = exec->globalData();
+ JSGlobalObject* dgo = exec->dynamicGlobalObject();
+ IdentifierTable* savedIdentifierTable = wtfThreadData().setCurrentIdentifierTable(globalData.identifierTable);
+
+ // One reference is held by JSGlobalObject, another added by JSGlobalContextRetain().
+ bool releasingContextGroup = globalData.refCount() == 2;
+ bool releasingGlobalObject = Heap::heap(dgo)->unprotect(dgo);
+ // If this is the last reference to a global data, it should also
+ // be the only remaining reference to the global object too!
+ ASSERT(!releasingContextGroup || releasingGlobalObject);
+
+ // An API 'JSGlobalContextRef' retains two things - a global object and a
+ // global data (or context group, in API terminology).
+ // * If this is the last reference to any contexts in the given context group,
+ // call destroy on the heap (the global data is being freed).
+ // * If this was the last reference to the global object, then unprotecting
+ // it may release a lot of GC memory - run the garbage collector now.
+ // * If there are more references remaining the the global object, then do nothing
+ // (specifically that is more protects, which we assume come from other JSGlobalContextRefs).
+ if (releasingContextGroup)
+ globalData.heap.destroy();
+ else if (releasingGlobalObject)
+ globalData.heap.collectAllGarbage();
+
+ globalData.deref();
+
+ wtfThreadData().setCurrentIdentifierTable(savedIdentifierTable);
+}
+
+JSObjectRef JSContextGetGlobalObject(JSContextRef ctx)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(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());
+}
+
+JSGlobalContextRef JSContextGetGlobalContext(JSContextRef ctx)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ return toGlobalRef(exec->lexicalGlobalObject()->globalExec());
+}
diff --git a/Source/JavaScriptCore/API/JSContextRef.h b/Source/JavaScriptCore/API/JSContextRef.h
new file mode 100644
index 0000000..c5c8a71
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSContextRef.h
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2006 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 JSContextRef_h
+#define JSContextRef_h
+
+#include <JavaScriptCore/JSObjectRef.h>
+#include <JavaScriptCore/JSValueRef.h>
+#include <JavaScriptCore/WebKitAvailability.h>
+
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*!
+@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_IN_WEBKIT_VERSION_4_0;
+
+/*!
+@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_IN_WEBKIT_VERSION_4_0;
+
+/*!
+@function
+@abstract Releases a JavaScript context group.
+@param group The JSContextGroup to release.
+*/
+JS_EXPORT void JSContextGroupRelease(JSContextGroupRef group) AVAILABLE_IN_WEBKIT_VERSION_4_0;
+
+/*!
+@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.
+
+ In WebKit version 4.0 and later, the context is created in a unique context group.
+ Therefore, scripts may execute in it concurrently with scripts executing in other contexts.
+ However, you may not use values created in the context in other 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) AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
+
+/*!
+@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_IN_WEBKIT_VERSION_4_0;
+
+/*!
+@function
+@abstract Retains a global JavaScript execution context.
+@param ctx The JSGlobalContext to retain.
+@result A JSGlobalContext that is the same as ctx.
+*/
+JS_EXPORT JSGlobalContextRef JSGlobalContextRetain(JSGlobalContextRef ctx);
+
+/*!
+@function
+@abstract Releases a global JavaScript execution context.
+@param ctx The JSGlobalContext to release.
+*/
+JS_EXPORT void JSGlobalContextRelease(JSGlobalContextRef ctx);
+
+/*!
+@function
+@abstract Gets the global object of a JavaScript execution context.
+@param ctx The JSContext whose global object you want to get.
+@result ctx's global object.
+*/
+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_IN_WEBKIT_VERSION_4_0;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSContextRef_h */
diff --git a/Source/JavaScriptCore/API/JSContextRefPrivate.h b/Source/JavaScriptCore/API/JSContextRefPrivate.h
new file mode 100644
index 0000000..ff014ec
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSContextRefPrivate.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2009 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 JSContextRefPrivate_h
+#define JSContextRefPrivate_h
+
+#include <JavaScriptCore/JSObjectRef.h>
+#include <JavaScriptCore/JSValueRef.h>
+#include <JavaScriptCore/WebKitAvailability.h>
+
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*!
+@function
+@abstract Gets the global context of a JavaScript execution context.
+@param ctx The JSContext whose global context you want to get.
+@result ctx's global context.
+*/
+JS_EXPORT JSGlobalContextRef JSContextGetGlobalContext(JSContextRef ctx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSContextRefPrivate_h */
diff --git a/Source/JavaScriptCore/API/JSObjectRef.cpp b/Source/JavaScriptCore/API/JSObjectRef.cpp
new file mode 100644
index 0000000..4198ca8
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSObjectRef.cpp
@@ -0,0 +1,544 @@
+/*
+ * 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
+ * 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 "JSObjectRef.h"
+#include "JSObjectRefPrivate.h"
+
+#include "APICast.h"
+#include "CodeBlock.h"
+#include "DateConstructor.h"
+#include "ErrorConstructor.h"
+#include "FunctionConstructor.h"
+#include "Identifier.h"
+#include "InitializeThreading.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 "RegExpConstructor.h"
+
+using namespace JSC;
+
+JSClassRef JSClassCreate(const JSClassDefinition* definition)
+{
+ initializeThreading();
+ RefPtr<OpaqueJSClass> jsClass = (definition->attributes & kJSClassAttributeNoAutomaticPrototype)
+ ? OpaqueJSClass::createNoAutomaticPrototype(definition)
+ : OpaqueJSClass::create(definition);
+
+ return jsClass.release().leakRef();
+}
+
+JSClassRef JSClassRetain(JSClassRef jsClass)
+{
+ jsClass->ref();
+ return jsClass;
+}
+
+void JSClassRelease(JSClassRef jsClass)
+{
+ jsClass->deref();
+}
+
+JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ if (!jsClass)
+ return toRef(new (exec) JSObject(exec->lexicalGlobalObject()->emptyObjectStructure())); // slightly more efficient
+
+ JSCallbackObject<JSObjectWithGlobalObject>* object = new (exec) JSCallbackObject<JSObjectWithGlobalObject>(exec, exec->lexicalGlobalObject(), exec->lexicalGlobalObject()->callbackObjectStructure(), jsClass, data);
+ if (JSObject* prototype = jsClass->prototype(exec))
+ object->setPrototype(prototype);
+
+ return toRef(object);
+}
+
+JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous");
+
+ return toRef(new (exec) JSCallbackFunction(exec, exec->lexicalGlobalObject(), callAsFunction, nameID));
+}
+
+JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsPrototype = jsClass ? jsClass->prototype(exec) : 0;
+ if (!jsPrototype)
+ jsPrototype = exec->lexicalGlobalObject()->objectPrototype();
+
+ JSCallbackConstructor* constructor = new (exec) JSCallbackConstructor(exec->lexicalGlobalObject(), 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)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ Identifier nameID = name ? name->identifier(&exec->globalData()) : Identifier(exec, "anonymous");
+
+ MarkedArgumentBuffer args;
+ for (unsigned i = 0; i < parameterCount; i++)
+ 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, 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);
+ APIEntryShim entryShim(exec);
+
+ JSObject* result;
+ if (argumentCount) {
+ MarkedArgumentBuffer argList;
+ for (size_t i = 0; i < argumentCount; ++i)
+ argList.append(toJS(exec, arguments[i]));
+
+ result = constructArray(exec, argList);
+ } else
+ result = constructEmptyArray(exec);
+
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, 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);
+ APIEntryShim entryShim(exec);
+
+ MarkedArgumentBuffer argList;
+ for (size_t i = 0; i < argumentCount; ++i)
+ argList.append(toJS(exec, arguments[i]));
+
+ JSObject* result = constructDate(exec, argList);
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ result = 0;
+ }
+
+ return toRef(result);
+}
+
+JSObjectRef JSObjectMakeError(JSContextRef ctx, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue message = argumentCount ? toJS(exec, arguments[0]) : jsUndefined();
+ Structure* errorStructure = exec->lexicalGlobalObject()->errorStructure();
+ JSObject* result = ErrorInstance::create(exec, errorStructure, message);
+
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, 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);
+ APIEntryShim entryShim(exec);
+
+ MarkedArgumentBuffer argList;
+ for (size_t i = 0; i < argumentCount; ++i)
+ argList.append(toJS(exec, arguments[i]));
+
+ JSObject* result = constructRegExp(exec, argList);
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ result = 0;
+ }
+
+ return toRef(result);
+}
+
+JSValueRef JSObjectGetPrototype(JSContextRef ctx, JSObjectRef object)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSObject* jsObject = toJS(object);
+ return toRef(exec, jsObject->prototype());
+}
+
+void JSObjectSetPrototype(JSContextRef ctx, JSObjectRef object, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSObject* jsObject = toJS(object);
+ JSValue jsValue = toJS(exec, value);
+
+ jsObject->setPrototypeWithCycleCheck(jsValue.isObject() ? jsValue : jsNull());
+}
+
+bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSObject* jsObject = toJS(object);
+
+ return jsObject->hasProperty(exec, propertyName->identifier(&exec->globalData()));
+}
+
+JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSObject* jsObject = toJS(object);
+
+ JSValue jsValue = jsObject->get(exec, propertyName->identifier(&exec->globalData()));
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ }
+ return toRef(exec, jsValue);
+}
+
+void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSObject* jsObject = toJS(object);
+ Identifier name(propertyName->identifier(&exec->globalData()));
+ JSValue jsValue = toJS(exec, value);
+
+ 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, exec->exception());
+ exec->clearException();
+ }
+}
+
+JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSObject* jsObject = toJS(object);
+
+ JSValue jsValue = jsObject->get(exec, propertyIndex);
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ }
+ return toRef(exec, jsValue);
+}
+
+
+void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSObject* jsObject = toJS(object);
+ JSValue jsValue = toJS(exec, value);
+
+ jsObject->put(exec, propertyIndex, jsValue);
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ }
+}
+
+bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSObject* jsObject = toJS(object);
+
+ bool result = jsObject->deleteProperty(exec, propertyName->identifier(&exec->globalData()));
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ }
+ return result;
+}
+
+void* JSObjectGetPrivate(JSObjectRef object)
+{
+ JSObject* jsObject = toJS(object);
+
+ if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info))
+ return static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->getPrivate();
+ else if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info))
+ return static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(jsObject)->getPrivate();
+
+ return 0;
+}
+
+bool JSObjectSetPrivate(JSObjectRef object, void* data)
+{
+ JSObject* jsObject = toJS(object);
+
+ if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info)) {
+ static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->setPrivate(data);
+ return true;
+ } else if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info)) {
+ static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(jsObject)->setPrivate(data);
+ return true;
+ }
+
+ return false;
+}
+
+JSValueRef JSObjectGetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+ JSObject* jsObject = toJS(object);
+ JSValue result;
+ Identifier name(propertyName->identifier(&exec->globalData()));
+ if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info))
+ result = static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->getPrivateProperty(name);
+ else if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info))
+ result = static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(jsObject)->getPrivateProperty(name);
+ return toRef(exec, result);
+}
+
+bool JSObjectSetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+ JSObject* jsObject = toJS(object);
+ JSValue jsValue = value ? toJS(exec, value) : JSValue();
+ Identifier name(propertyName->identifier(&exec->globalData()));
+ if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info)) {
+ static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->setPrivateProperty(name, jsValue);
+ return true;
+ }
+ if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info)) {
+ static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(jsObject)->setPrivateProperty(name, jsValue);
+ return true;
+ }
+ return false;
+}
+
+bool JSObjectDeletePrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+ JSObject* jsObject = toJS(object);
+ Identifier name(propertyName->identifier(&exec->globalData()));
+ if (jsObject->inherits(&JSCallbackObject<JSGlobalObject>::info)) {
+ static_cast<JSCallbackObject<JSGlobalObject>*>(jsObject)->deletePrivateProperty(name);
+ return true;
+ }
+ if (jsObject->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info)) {
+ static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(jsObject)->deletePrivateProperty(name);
+ return true;
+ }
+ return false;
+}
+
+bool JSObjectIsFunction(JSContextRef, JSObjectRef object)
+{
+ CallData callData;
+ return toJS(object)->getCallData(callData) != CallTypeNone;
+}
+
+JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSObject* jsObject = toJS(object);
+ JSObject* jsThisObject = toJS(thisObject);
+
+ if (!jsThisObject)
+ jsThisObject = exec->globalThisValue();
+
+ MarkedArgumentBuffer argList;
+ for (size_t i = 0; i < argumentCount; i++)
+ argList.append(toJS(exec, arguments[i]));
+
+ CallData callData;
+ CallType callType = jsObject->getCallData(callData);
+ if (callType == CallTypeNone)
+ return 0;
+
+ JSValueRef result = toRef(exec, call(exec, jsObject, callType, callData, jsThisObject, argList));
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ result = 0;
+ }
+ return result;
+}
+
+bool JSObjectIsConstructor(JSContextRef, JSObjectRef object)
+{
+ JSObject* jsObject = toJS(object);
+ ConstructData constructData;
+ return jsObject->getConstructData(constructData) != ConstructTypeNone;
+}
+
+JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSObject* jsObject = toJS(object);
+
+ ConstructData constructData;
+ ConstructType constructType = jsObject->getConstructData(constructData);
+ if (constructType == ConstructTypeNone)
+ return 0;
+
+ MarkedArgumentBuffer argList;
+ for (size_t i = 0; i < argumentCount; i++)
+ argList.append(toJS(exec, arguments[i]));
+ JSObjectRef result = toRef(construct(exec, jsObject, constructType, constructData, argList));
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ result = 0;
+ }
+ return result;
+}
+
+struct OpaqueJSPropertyNameArray : FastAllocBase {
+ OpaqueJSPropertyNameArray(JSGlobalData* globalData)
+ : refCount(0)
+ , globalData(globalData)
+ {
+ }
+
+ unsigned refCount;
+ JSGlobalData* globalData;
+ Vector<JSRetainPtr<JSStringRef> > array;
+};
+
+JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef object)
+{
+ JSObject* jsObject = toJS(object);
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSGlobalData* globalData = &exec->globalData();
+
+ JSPropertyNameArrayRef propertyNames = new OpaqueJSPropertyNameArray(globalData);
+ PropertyNameArray array(globalData);
+ jsObject->getPropertyNames(exec, array);
+
+ size_t size = array.size();
+ propertyNames->array.reserveInitialCapacity(size);
+ for (size_t i = 0; i < size; ++i)
+ propertyNames->array.append(JSRetainPtr<JSStringRef>(Adopt, OpaqueJSString::create(array[i].ustring()).leakRef()));
+
+ return JSPropertyNameArrayRetain(propertyNames);
+}
+
+JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array)
+{
+ ++array->refCount;
+ return array;
+}
+
+void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array)
+{
+ if (--array->refCount == 0) {
+ APIEntryShim entryShim(array->globalData, false);
+ delete array;
+ }
+}
+
+size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array)
+{
+ return array->array.size();
+}
+
+JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index)
+{
+ return array->array[static_cast<unsigned>(index)].get();
+}
+
+void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef array, JSStringRef propertyName)
+{
+ PropertyNameArray* propertyNames = toJS(array);
+ APIEntryShim entryShim(propertyNames->globalData());
+ propertyNames->add(propertyName->identifier(propertyNames->globalData()));
+}
diff --git a/Source/JavaScriptCore/API/JSObjectRef.h b/Source/JavaScriptCore/API/JSObjectRef.h
new file mode 100644
index 0000000..3e8b0eb
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSObjectRef.h
@@ -0,0 +1,694 @@
+/*
+ * 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
+ * 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 JSObjectRef_h
+#define JSObjectRef_h
+
+#include <JavaScriptCore/JSBase.h>
+#include <JavaScriptCore/JSValueRef.h>
+#include <JavaScriptCore/WebKitAvailability.h>
+
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+#include <stddef.h> /* for size_t */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*!
+@enum JSPropertyAttribute
+@constant kJSPropertyAttributeNone Specifies that a property has no special attributes.
+@constant kJSPropertyAttributeReadOnly Specifies that a property is read-only.
+@constant kJSPropertyAttributeDontEnum Specifies that a property should not be enumerated by JSPropertyEnumerators and JavaScript for...in loops.
+@constant kJSPropertyAttributeDontDelete Specifies that the delete operation should fail on a property.
+*/
+enum {
+ kJSPropertyAttributeNone = 0,
+ kJSPropertyAttributeReadOnly = 1 << 1,
+ kJSPropertyAttributeDontEnum = 1 << 2,
+ kJSPropertyAttributeDontDelete = 1 << 3
+};
+
+/*!
+@typedef JSPropertyAttributes
+@abstract A set of JSPropertyAttributes. Combine multiple attributes by logically ORing them together.
+*/
+typedef unsigned JSPropertyAttributes;
+
+/*!
+@enum JSClassAttribute
+@constant kJSClassAttributeNone Specifies that a class has no special attributes.
+@constant kJSClassAttributeNoAutomaticPrototype Specifies that a class should not automatically generate a shared prototype for its instance objects. Use kJSClassAttributeNoAutomaticPrototype in combination with JSObjectSetPrototype to manage prototypes manually.
+*/
+enum {
+ kJSClassAttributeNone = 0,
+ kJSClassAttributeNoAutomaticPrototype = 1 << 1
+};
+
+/*!
+@typedef JSClassAttributes
+@abstract A set of JSClassAttributes. Combine multiple attributes by logically ORing them together.
+*/
+typedef unsigned JSClassAttributes;
+
+/*!
+@typedef JSObjectInitializeCallback
+@abstract The callback invoked when an object is first created.
+@param ctx The execution context to use.
+@param object The JSObject being created.
+@discussion If you named your function Initialize, you would declare it like this:
+
+void Initialize(JSContextRef ctx, JSObjectRef object);
+
+Unlike the other object callbacks, the initialize callback is called on the least
+derived class (the parent class) first, and the most derived class last.
+*/
+typedef void
+(*JSObjectInitializeCallback) (JSContextRef ctx, JSObjectRef object);
+
+/*!
+@typedef JSObjectFinalizeCallback
+@abstract The callback invoked when an object is finalized (prepared for garbage collection). An object may be finalized on any thread.
+@param object The JSObject being finalized.
+@discussion If you named your function Finalize, you would declare it like this:
+
+void Finalize(JSObjectRef object);
+
+The finalize callback is called on the most derived class first, and the least
+derived class (the parent class) last.
+
+You must not call any function that may cause a garbage collection or an allocation
+of a garbage collected object from within a JSObjectFinalizeCallback. This includes
+all functions that have a JSContextRef parameter.
+*/
+typedef void
+(*JSObjectFinalizeCallback) (JSObjectRef object);
+
+/*!
+@typedef JSObjectHasPropertyCallback
+@abstract The callback invoked when determining whether an object has a property.
+@param ctx The execution context to use.
+@param object The JSObject to search for the property.
+@param propertyName A JSString containing the name of the property look up.
+@result true if object has the property, otherwise false.
+@discussion If you named your function HasProperty, you would declare it like this:
+
+bool HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
+
+If this function returns false, the hasProperty request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.
+
+This callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value would be expensive.
+
+If this callback is NULL, the getProperty callback will be used to service hasProperty requests.
+*/
+typedef bool
+(*JSObjectHasPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
+
+/*!
+@typedef JSObjectGetPropertyCallback
+@abstract The callback invoked when getting a property's value.
+@param ctx The execution context to use.
+@param object The JSObject to search for the property.
+@param propertyName A JSString containing the name of the property to get.
+@param exception A pointer to a JSValueRef in which to return an exception, if any.
+@result The property's value if object has the property, otherwise NULL.
+@discussion If you named your function GetProperty, you would declare it like this:
+
+JSValueRef GetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+If this function returns NULL, the get request forwards to object's statically declared properties, then its parent class chain (which includes the default object class), then its prototype chain.
+*/
+typedef JSValueRef
+(*JSObjectGetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+/*!
+@typedef JSObjectSetPropertyCallback
+@abstract The callback invoked when setting a property's value.
+@param ctx The execution context to use.
+@param object The JSObject on which to set the property's value.
+@param propertyName A JSString containing the name of the property to set.
+@param value A JSValue to use as the property's value.
+@param exception A pointer to a JSValueRef in which to return an exception, if any.
+@result true if the property was set, otherwise false.
+@discussion If you named your function SetProperty, you would declare it like this:
+
+bool SetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
+
+If this function returns false, the set request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).
+*/
+typedef bool
+(*JSObjectSetPropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception);
+
+/*!
+@typedef JSObjectDeletePropertyCallback
+@abstract The callback invoked when deleting a property.
+@param ctx The execution context to use.
+@param object The JSObject in which to delete the property.
+@param propertyName A JSString containing the name of the property to delete.
+@param exception A pointer to a JSValueRef in which to return an exception, if any.
+@result true if propertyName was successfully deleted, otherwise false.
+@discussion If you named your function DeleteProperty, you would declare it like this:
+
+bool DeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+If this function returns false, the delete request forwards to object's statically declared properties, then its parent class chain (which includes the default object class).
+*/
+typedef bool
+(*JSObjectDeletePropertyCallback) (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+/*!
+@typedef JSObjectGetPropertyNamesCallback
+@abstract The callback invoked when collecting the names of an object's properties.
+@param ctx The execution context to use.
+@param object The JSObject whose property names are being collected.
+@param accumulator A JavaScript property name accumulator in which to accumulate the names of object's properties.
+@discussion If you named your function GetPropertyNames, you would declare it like this:
+
+void GetPropertyNames(JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
+
+Property name accumulators are used by JSObjectCopyPropertyNames and JavaScript for...in loops.
+
+Use JSPropertyNameAccumulatorAddName to add property names to accumulator. A class's getPropertyNames callback only needs to provide the names of properties that the class vends through a custom getProperty or setProperty callback. Other properties, including statically declared properties, properties vended by other classes, and properties belonging to object's prototype, are added independently.
+*/
+typedef void
+(*JSObjectGetPropertyNamesCallback) (JSContextRef ctx, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames);
+
+/*!
+@typedef JSObjectCallAsFunctionCallback
+@abstract The callback invoked when an object is called as a function.
+@param ctx The execution context to use.
+@param function A JSObject that is the function being called.
+@param thisObject A JSObject that is the 'this' variable in the function's scope.
+@param argumentCount An integer count of the number of arguments in arguments.
+@param arguments A JSValue array of the arguments passed to the function.
+@param exception A pointer to a JSValueRef in which to return an exception, if any.
+@result A JSValue that is the function's return value.
+@discussion If you named your function CallAsFunction, you would declare it like this:
+
+JSValueRef CallAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+If your callback were invoked by the JavaScript expression 'myObject.myFunction()', function would be set to myFunction, and thisObject would be set to myObject.
+
+If this callback is NULL, calling your object as a function will throw an exception.
+*/
+typedef JSValueRef
+(*JSObjectCallAsFunctionCallback) (JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+/*!
+@typedef JSObjectCallAsConstructorCallback
+@abstract The callback invoked when an object is used as a constructor in a 'new' expression.
+@param ctx The execution context to use.
+@param constructor A JSObject that is the constructor being called.
+@param argumentCount An integer count of the number of arguments in arguments.
+@param arguments A JSValue array of the arguments passed to the function.
+@param exception A pointer to a JSValueRef in which to return an exception, if any.
+@result A JSObject that is the constructor's return value.
+@discussion If you named your function CallAsConstructor, you would declare it like this:
+
+JSObjectRef CallAsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+If your callback were invoked by the JavaScript expression 'new myConstructor()', constructor would be set to myConstructor.
+
+If this callback is NULL, using your object as a constructor in a 'new' expression will throw an exception.
+*/
+typedef JSObjectRef
+(*JSObjectCallAsConstructorCallback) (JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+/*!
+@typedef JSObjectHasInstanceCallback
+@abstract hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
+@param ctx The execution context to use.
+@param constructor The JSObject that is the target of the 'instanceof' expression.
+@param possibleInstance The JSValue being tested to determine if it is an instance of constructor.
+@param exception A pointer to a JSValueRef in which to return an exception, if any.
+@result true if possibleInstance is an instance of constructor, otherwise false.
+@discussion If you named your function HasInstance, you would declare it like this:
+
+bool HasInstance(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
+
+If your callback were invoked by the JavaScript expression 'someValue instanceof myObject', constructor would be set to myObject and possibleInstance would be set to someValue.
+
+If this callback is NULL, 'instanceof' expressions that target your object will return false.
+
+Standard JavaScript practice calls for objects that implement the callAsConstructor callback to implement the hasInstance callback as well.
+*/
+typedef bool
+(*JSObjectHasInstanceCallback) (JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception);
+
+/*!
+@typedef JSObjectConvertToTypeCallback
+@abstract The callback invoked when converting an object to a particular JavaScript type.
+@param ctx The execution context to use.
+@param object The JSObject to convert.
+@param type A JSType specifying the JavaScript type to convert to.
+@param exception A pointer to a JSValueRef in which to return an exception, if any.
+@result The objects's converted value, or NULL if the object was not converted.
+@discussion If you named your function ConvertToType, you would declare it like this:
+
+JSValueRef ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
+
+If this function returns false, the conversion request forwards to object's parent class chain (which includes the default object class).
+
+This function is only invoked when converting an object to number or string. An object converted to boolean is 'true.' An object converted to object is itself.
+*/
+typedef JSValueRef
+(*JSObjectConvertToTypeCallback) (JSContextRef ctx, JSObjectRef object, JSType type, JSValueRef* exception);
+
+/*!
+@struct JSStaticValue
+@abstract This structure describes a statically declared value property.
+@field name A null-terminated UTF8 string containing the property's name.
+@field getProperty A JSObjectGetPropertyCallback to invoke when getting the property's value.
+@field setProperty A JSObjectSetPropertyCallback to invoke when setting the property's value. May be NULL if the ReadOnly attribute is set.
+@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
+*/
+typedef struct {
+ const char* const name;
+ JSObjectGetPropertyCallback getProperty;
+ JSObjectSetPropertyCallback setProperty;
+ JSPropertyAttributes attributes;
+} JSStaticValue;
+
+/*!
+@struct JSStaticFunction
+@abstract This structure describes a statically declared function property.
+@field name A null-terminated UTF8 string containing the property's name.
+@field callAsFunction A JSObjectCallAsFunctionCallback to invoke when the property is called as a function.
+@field attributes A logically ORed set of JSPropertyAttributes to give to the property.
+*/
+typedef struct {
+ const char* const name;
+ JSObjectCallAsFunctionCallback callAsFunction;
+ JSPropertyAttributes attributes;
+} JSStaticFunction;
+
+/*!
+@struct JSClassDefinition
+@abstract This structure contains properties and callbacks that define a type of object. All fields other than the version field are optional. Any pointer may be NULL.
+@field version The version number of this structure. The current version is 0.
+@field attributes A logically ORed set of JSClassAttributes to give to the class.
+@field className A null-terminated UTF8 string containing the class's name.
+@field parentClass A JSClass to set as the class's parent class. Pass NULL use the default object class.
+@field staticValues A JSStaticValue array containing the class's statically declared value properties. Pass NULL to specify no statically declared value properties. The array must be terminated by a JSStaticValue whose name field is NULL.
+@field staticFunctions A JSStaticFunction array containing the class's statically declared function properties. Pass NULL to specify no statically declared function properties. The array must be terminated by a JSStaticFunction whose name field is NULL.
+@field initialize The callback invoked when an object is first created. Use this callback to initialize the object.
+@field finalize The callback invoked when an object is finalized (prepared for garbage collection). Use this callback to release resources allocated for the object, and perform other cleanup.
+@field hasProperty The callback invoked when determining whether an object has a property. If this field is NULL, getProperty is called instead. The hasProperty callback enables optimization in cases where only a property's existence needs to be known, not its value, and computing its value is expensive.
+@field getProperty The callback invoked when getting a property's value.
+@field setProperty The callback invoked when setting a property's value.
+@field deleteProperty The callback invoked when deleting a property.
+@field getPropertyNames The callback invoked when collecting the names of an object's properties.
+@field callAsFunction The callback invoked when an object is called as a function.
+@field hasInstance The callback invoked when an object is used as the target of an 'instanceof' expression.
+@field callAsConstructor The callback invoked when an object is used as a constructor in a 'new' expression.
+@field convertToType The callback invoked when converting an object to a particular JavaScript type.
+@discussion The staticValues and staticFunctions arrays are the simplest and most efficient means for vending custom properties. Statically declared properties autmatically service requests like getProperty, setProperty, and getPropertyNames. Property access callbacks are required only to implement unusual properties, like array indexes, whose names are not known at compile-time.
+
+If you named your getter function "GetX" and your setter function "SetX", you would declare a JSStaticValue array containing "X" like this:
+
+JSStaticValue StaticValueArray[] = {
+ { "X", GetX, SetX, kJSPropertyAttributeNone },
+ { 0, 0, 0, 0 }
+};
+
+Standard JavaScript practice calls for storing function objects in prototypes, so they can be shared. The default JSClass created by JSClassCreate follows this idiom, instantiating objects with a shared, automatically generating prototype containing the class's function objects. The kJSClassAttributeNoAutomaticPrototype attribute specifies that a JSClass should not automatically generate such a prototype. The resulting JSClass instantiates objects with the default object prototype, and gives each instance object its own copy of the class's function objects.
+
+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 */
+ JSClassAttributes attributes;
+
+ const char* className;
+ JSClassRef parentClass;
+
+ const JSStaticValue* staticValues;
+ const JSStaticFunction* staticFunctions;
+
+ JSObjectInitializeCallback initialize;
+ JSObjectFinalizeCallback finalize;
+ JSObjectHasPropertyCallback hasProperty;
+ JSObjectGetPropertyCallback getProperty;
+ JSObjectSetPropertyCallback setProperty;
+ JSObjectDeletePropertyCallback deleteProperty;
+ JSObjectGetPropertyNamesCallback getPropertyNames;
+ JSObjectCallAsFunctionCallback callAsFunction;
+ JSObjectCallAsConstructorCallback callAsConstructor;
+ JSObjectHasInstanceCallback hasInstance;
+ JSObjectConvertToTypeCallback convertToType;
+} JSClassDefinition;
+
+/*!
+@const kJSClassDefinitionEmpty
+@abstract A JSClassDefinition structure of the current version, filled with NULL pointers and having no attributes.
+@discussion Use this constant as a convenience when creating class definitions. For example, to create a class definition with only a finalize method:
+
+JSClassDefinition definition = kJSClassDefinitionEmpty;
+definition.finalize = Finalize;
+*/
+JS_EXPORT extern const JSClassDefinition kJSClassDefinitionEmpty;
+
+/*!
+@function
+@abstract Creates a JavaScript class suitable for use with JSObjectMake.
+@param definition A JSClassDefinition that defines the class.
+@result A JSClass with the given definition. Ownership follows the Create Rule.
+*/
+JS_EXPORT JSClassRef JSClassCreate(const JSClassDefinition* definition);
+
+/*!
+@function
+@abstract Retains a JavaScript class.
+@param jsClass The JSClass to retain.
+@result A JSClass that is the same as jsClass.
+*/
+JS_EXPORT JSClassRef JSClassRetain(JSClassRef jsClass);
+
+/*!
+@function
+@abstract Releases a JavaScript class.
+@param jsClass The JSClass to release.
+*/
+JS_EXPORT void JSClassRelease(JSClassRef jsClass);
+
+/*!
+@function
+@abstract Creates a JavaScript object.
+@param ctx The execution context to use.
+@param jsClass The JSClass to assign to the object. Pass NULL to use the default object class.
+@param data A void* to set as the object's private data. Pass NULL to specify no private data.
+@result A JSObject with the given class and private data.
+@discussion The default object class does not allocate storage for private data, so you must provide a non-NULL jsClass to JSObjectMake if you want your object to be able to store private data.
+
+data is set on the created object before the intialize methods in its class chain are called. This enables the initialize methods to retrieve and manipulate data through JSObjectGetPrivate.
+*/
+JS_EXPORT JSObjectRef JSObjectMake(JSContextRef ctx, JSClassRef jsClass, void* data);
+
+/*!
+@function
+@abstract Convenience method for creating a JavaScript function with a given callback as its implementation.
+@param ctx The execution context to use.
+@param name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
+@param callAsFunction The JSObjectCallAsFunctionCallback to invoke when the function is called.
+@result A JSObject that is a function. The object's prototype will be the default function prototype.
+*/
+JS_EXPORT JSObjectRef JSObjectMakeFunctionWithCallback(JSContextRef ctx, JSStringRef name, JSObjectCallAsFunctionCallback callAsFunction);
+
+/*!
+@function
+@abstract Convenience method for creating a JavaScript constructor.
+@param ctx The execution context to use.
+@param jsClass A JSClass that is the class your constructor will assign to the objects its constructs. jsClass will be used to set the constructor's .prototype property, and to evaluate 'instanceof' expressions. Pass NULL to use the default object class.
+@param callAsConstructor A JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor.
+@result A JSObject that is a constructor. The object's prototype will be the default object prototype.
+@discussion The default object constructor takes no arguments and constructs an object of class jsClass with no private data.
+*/
+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_IN_WEBKIT_VERSION_4_0;
+
+/*!
+ @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_IN_WEBKIT_VERSION_4_0;
+
+/*!
+ @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_IN_WEBKIT_VERSION_4_0;
+
+/*!
+ @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_IN_WEBKIT_VERSION_4_0;
+
+/*!
+@function
+@abstract Creates a function with a given script as its body.
+@param ctx The execution context to use.
+@param name A JSString containing the function's name. This will be used when converting the function to string. Pass NULL to create an anonymous function.
+@param parameterCount An integer count of the number of parameter names in parameterNames.
+@param parameterNames A JSString array containing the names of the function's parameters. Pass NULL if parameterCount is 0.
+@param body A JSString containing the script to use as the function's body.
+@param sourceURL A JSString containing a URL for the script's source file. This is only used when reporting exceptions. Pass NULL if you do not care to include source file information in exceptions.
+@param startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions.
+@param exception A pointer to a JSValueRef in which to store a syntax error exception, if any. Pass NULL if you do not care to store a syntax error exception.
+@result A JSObject that is a function, or NULL if either body or parameterNames contains a syntax error. The object's prototype will be the default function prototype.
+@discussion Use this method when you want to execute a script repeatedly, to avoid the cost of re-parsing the script before each execution.
+*/
+JS_EXPORT JSObjectRef JSObjectMakeFunction(JSContextRef ctx, JSStringRef name, unsigned parameterCount, const JSStringRef parameterNames[], JSStringRef body, JSStringRef sourceURL, int startingLineNumber, JSValueRef* exception);
+
+/*!
+@function
+@abstract Gets an object's prototype.
+@param ctx The execution context to use.
+@param object A JSObject whose prototype you want to get.
+@result A JSValue that is the object's prototype.
+*/
+JS_EXPORT JSValueRef JSObjectGetPrototype(JSContextRef ctx, JSObjectRef object);
+
+/*!
+@function
+@abstract Sets an object's prototype.
+@param ctx The execution context to use.
+@param object The JSObject whose prototype you want to set.
+@param value A JSValue to set as the object's prototype.
+*/
+JS_EXPORT void JSObjectSetPrototype(JSContextRef ctx, JSObjectRef object, JSValueRef value);
+
+/*!
+@function
+@abstract Tests whether an object has a given property.
+@param object The JSObject to test.
+@param propertyName A JSString containing the property's name.
+@result true if the object has a property whose name matches propertyName, otherwise false.
+*/
+JS_EXPORT bool JSObjectHasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
+
+/*!
+@function
+@abstract Gets a property from an object.
+@param ctx The execution context to use.
+@param object The JSObject whose property you want to get.
+@param propertyName A JSString containing the property's name.
+@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 The property's value if object has the property, otherwise the undefined value.
+*/
+JS_EXPORT JSValueRef JSObjectGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+/*!
+@function
+@abstract Sets a property on an object.
+@param ctx The execution context to use.
+@param object The JSObject whose property you want to set.
+@param propertyName A JSString containing the property's name.
+@param value A JSValue to use as the property's value.
+@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.
+@param attributes A logically ORed set of JSPropertyAttributes to give to the property.
+*/
+JS_EXPORT void JSObjectSetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSPropertyAttributes attributes, JSValueRef* exception);
+
+/*!
+@function
+@abstract Deletes a property from an object.
+@param ctx The execution context to use.
+@param object The JSObject whose property you want to delete.
+@param propertyName A JSString containing the property's name.
+@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 true if the delete operation succeeds, otherwise false (for example, if the property has the kJSPropertyAttributeDontDelete attribute set).
+*/
+JS_EXPORT bool JSObjectDeleteProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception);
+
+/*!
+@function
+@abstract Gets a property from an object by numeric index.
+@param ctx The execution context to use.
+@param object The JSObject whose property you want to get.
+@param propertyIndex An integer value that is the property's name.
+@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 The property's value if object has the property, otherwise the undefined value.
+@discussion Calling JSObjectGetPropertyAtIndex is equivalent to calling JSObjectGetProperty with a string containing propertyIndex, but JSObjectGetPropertyAtIndex provides optimized access to numeric properties.
+*/
+JS_EXPORT JSValueRef JSObjectGetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef* exception);
+
+/*!
+@function
+@abstract Sets a property on an object by numeric index.
+@param ctx The execution context to use.
+@param object The JSObject whose property you want to set.
+@param propertyIndex The property's name as a number.
+@param value A JSValue to use as the property's value.
+@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.
+@discussion Calling JSObjectSetPropertyAtIndex is equivalent to calling JSObjectSetProperty with a string containing propertyIndex, but JSObjectSetPropertyAtIndex provides optimized access to numeric properties.
+*/
+JS_EXPORT void JSObjectSetPropertyAtIndex(JSContextRef ctx, JSObjectRef object, unsigned propertyIndex, JSValueRef value, JSValueRef* exception);
+
+/*!
+@function
+@abstract Gets an object's private data.
+@param object A JSObject whose private data you want to get.
+@result A void* that is the object's private data, if the object has private data, otherwise NULL.
+*/
+JS_EXPORT void* JSObjectGetPrivate(JSObjectRef object);
+
+/*!
+@function
+@abstract Sets a pointer to private data on an object.
+@param object The JSObject whose private data you want to set.
+@param data A void* to set as the object's private data.
+@result true if object can store private data, otherwise false.
+@discussion The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data.
+*/
+JS_EXPORT bool JSObjectSetPrivate(JSObjectRef object, void* data);
+
+/*!
+@function
+@abstract Tests whether an object can be called as a function.
+@param ctx The execution context to use.
+@param object The JSObject to test.
+@result true if the object can be called as a function, otherwise false.
+*/
+JS_EXPORT bool JSObjectIsFunction(JSContextRef ctx, JSObjectRef object);
+
+/*!
+@function
+@abstract Calls an object as a function.
+@param ctx The execution context to use.
+@param object The JSObject to call as a function.
+@param thisObject The object to use as "this," or NULL to use the global object as "this."
+@param argumentCount An integer count of the number of arguments in arguments.
+@param arguments A JSValue array of arguments to pass to the function. 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 The JSValue that results from calling object as a function, or NULL if an exception is thrown or object is not a function.
+*/
+JS_EXPORT JSValueRef JSObjectCallAsFunction(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+/*!
+@function
+@abstract Tests whether an object can be called as a constructor.
+@param ctx The execution context to use.
+@param object The JSObject to test.
+@result true if the object can be called as a constructor, otherwise false.
+*/
+JS_EXPORT bool JSObjectIsConstructor(JSContextRef ctx, JSObjectRef object);
+
+/*!
+@function
+@abstract Calls an object as a constructor.
+@param ctx The execution context to use.
+@param object The JSObject to call as a constructor.
+@param argumentCount An integer count of the number of arguments in arguments.
+@param arguments A JSValue array of arguments to pass to the 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 The JSObject that results from calling object as a constructor, or NULL if an exception is thrown or object is not a constructor.
+*/
+JS_EXPORT JSObjectRef JSObjectCallAsConstructor(JSContextRef ctx, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+/*!
+@function
+@abstract Gets the names of an object's enumerable properties.
+@param ctx The execution context to use.
+@param object The object whose property names you want to get.
+@result A JSPropertyNameArray containing the names object's enumerable properties. Ownership follows the Create Rule.
+*/
+JS_EXPORT JSPropertyNameArrayRef JSObjectCopyPropertyNames(JSContextRef ctx, JSObjectRef object);
+
+/*!
+@function
+@abstract Retains a JavaScript property name array.
+@param array The JSPropertyNameArray to retain.
+@result A JSPropertyNameArray that is the same as array.
+*/
+JS_EXPORT JSPropertyNameArrayRef JSPropertyNameArrayRetain(JSPropertyNameArrayRef array);
+
+/*!
+@function
+@abstract Releases a JavaScript property name array.
+@param array The JSPropetyNameArray to release.
+*/
+JS_EXPORT void JSPropertyNameArrayRelease(JSPropertyNameArrayRef array);
+
+/*!
+@function
+@abstract Gets a count of the number of items in a JavaScript property name array.
+@param array The array from which to retrieve the count.
+@result An integer count of the number of names in array.
+*/
+JS_EXPORT size_t JSPropertyNameArrayGetCount(JSPropertyNameArrayRef array);
+
+/*!
+@function
+@abstract Gets a property name at a given index in a JavaScript property name array.
+@param array The array from which to retrieve the property name.
+@param index The index of the property name to retrieve.
+@result A JSStringRef containing the property name.
+*/
+JS_EXPORT JSStringRef JSPropertyNameArrayGetNameAtIndex(JSPropertyNameArrayRef array, size_t index);
+
+/*!
+@function
+@abstract Adds a property name to a JavaScript property name accumulator.
+@param accumulator The accumulator object to which to add the property name.
+@param propertyName The property name to add.
+*/
+JS_EXPORT void JSPropertyNameAccumulatorAddName(JSPropertyNameAccumulatorRef accumulator, JSStringRef propertyName);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSObjectRef_h */
diff --git a/Source/JavaScriptCore/API/JSObjectRefPrivate.h b/Source/JavaScriptCore/API/JSObjectRefPrivate.h
new file mode 100644
index 0000000..32e80ab
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSObjectRefPrivate.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 ITS 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 JSObjectRefPrivate_h
+#define JSObjectRefPrivate_h
+
+#include <JavaScriptCore/JSObjectRef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*!
+ @function
+ @abstract Sets a private property on an object. This private property cannot be accessed from within JavaScript.
+ @param ctx The execution context to use.
+ @param object The JSObject whose private property you want to set.
+ @param propertyName A JSString containing the property's name.
+ @param value A JSValue to use as the property's value. This may be NULL.
+ @result true if object can store private data, otherwise false.
+ @discussion This API allows you to store JS values directly an object in a way that will be ensure that they are kept alive without exposing them to JavaScript code and without introducing the reference cycles that may occur when using JSValueProtect.
+
+ The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private properties.
+ */
+JS_EXPORT bool JSObjectSetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value);
+
+/*!
+ @function
+ @abstract Gets a private property from an object.
+ @param ctx The execution context to use.
+ @param object The JSObject whose private property you want to get.
+ @param propertyName A JSString containing the property's name.
+ @result The property's value if object has the property, otherwise NULL.
+ */
+JS_EXPORT JSValueRef JSObjectGetPrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
+
+/*!
+ @function
+ @abstract Deletes a private property from an object.
+ @param ctx The execution context to use.
+ @param object The JSObject whose private property you want to delete.
+ @param propertyName A JSString containing the property's name.
+ @result true if object can store private data, otherwise false.
+ @discussion The default object class does not allocate storage for private data. Only objects created with a non-NULL JSClass can store private data.
+ */
+JS_EXPORT bool JSObjectDeletePrivateProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // JSObjectRefPrivate_h
diff --git a/Source/JavaScriptCore/API/JSProfilerPrivate.cpp b/Source/JavaScriptCore/API/JSProfilerPrivate.cpp
new file mode 100644
index 0000000..ea277f0
--- /dev/null
+++ b/Source/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/Source/JavaScriptCore/API/JSProfilerPrivate.h b/Source/JavaScriptCore/API/JSProfilerPrivate.h
new file mode 100644
index 0000000..b3fe533
--- /dev/null
+++ b/Source/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/Source/JavaScriptCore/API/JSRetainPtr.h b/Source/JavaScriptCore/API/JSRetainPtr.h
new file mode 100644
index 0000000..a884f38
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSRetainPtr.h
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2005, 2006, 2007, 2010 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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 JSRetainPtr_h
+#define JSRetainPtr_h
+
+#include <JavaScriptCore/JSStringRef.h>
+#include <algorithm>
+
+inline void JSRetain(JSStringRef string) { JSStringRetain(string); }
+inline void JSRelease(JSStringRef string) { JSStringRelease(string); }
+
+enum AdoptTag { Adopt };
+
+template<typename T> class JSRetainPtr {
+public:
+ JSRetainPtr() : m_ptr(0) { }
+ JSRetainPtr(T ptr) : m_ptr(ptr) { if (ptr) JSRetain(ptr); }
+ JSRetainPtr(AdoptTag, T ptr) : m_ptr(ptr) { }
+ JSRetainPtr(const JSRetainPtr&);
+ template<typename U> JSRetainPtr(const JSRetainPtr<U>&);
+ ~JSRetainPtr();
+
+ T get() const { return m_ptr; }
+
+ void clear();
+ T leakRef();
+
+ T operator->() const { return m_ptr; }
+
+ bool operator!() const { return !m_ptr; }
+
+ // This conversion operator allows implicit conversion to bool but not to other integer types.
+ typedef T JSRetainPtr::*UnspecifiedBoolType;
+ operator UnspecifiedBoolType() const { return m_ptr ? &JSRetainPtr::m_ptr : 0; }
+
+ JSRetainPtr& operator=(const JSRetainPtr&);
+ template<typename U> JSRetainPtr& operator=(const JSRetainPtr<U>&);
+ JSRetainPtr& operator=(T);
+ template<typename U> JSRetainPtr& operator=(U*);
+
+ void adopt(T);
+
+ void swap(JSRetainPtr&);
+
+ // FIXME: Remove releaseRef once we change all callers to call leakRef instead.
+ T releaseRef() { return leakRef(); }
+
+private:
+ T m_ptr;
+};
+
+template<typename T> inline JSRetainPtr<T>::JSRetainPtr(const JSRetainPtr& o)
+ : m_ptr(o.m_ptr)
+{
+ if (m_ptr)
+ JSRetain(m_ptr);
+}
+
+template<typename T> template<typename U> inline JSRetainPtr<T>::JSRetainPtr(const JSRetainPtr<U>& o)
+ : m_ptr(o.get())
+{
+ if (m_ptr)
+ JSRetain(m_ptr);
+}
+
+template<typename T> inline JSRetainPtr<T>::~JSRetainPtr()
+{
+ if (m_ptr)
+ JSRelease(m_ptr);
+}
+
+template<typename T> inline void JSRetainPtr<T>::clear()
+{
+ if (T ptr = m_ptr) {
+ m_ptr = 0;
+ JSRelease(ptr);
+ }
+}
+
+template<typename T> inline T JSRetainPtr<T>::leakRef()
+{
+ T ptr = m_ptr;
+ m_ptr = 0;
+ return ptr;
+}
+
+template<typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<T>& o)
+{
+ T optr = o.get();
+ if (optr)
+ JSRetain(optr);
+ T ptr = m_ptr;
+ m_ptr = optr;
+ if (ptr)
+ JSRelease(ptr);
+ return *this;
+}
+
+template<typename T> template<typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<U>& o)
+{
+ T optr = o.get();
+ if (optr)
+ JSRetain(optr);
+ T ptr = m_ptr;
+ m_ptr = optr;
+ if (ptr)
+ JSRelease(ptr);
+ return *this;
+}
+
+template<typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(T optr)
+{
+ if (optr)
+ JSRetain(optr);
+ T ptr = m_ptr;
+ m_ptr = optr;
+ if (ptr)
+ JSRelease(ptr);
+ return *this;
+}
+
+template<typename T> inline void JSRetainPtr<T>::adopt(T optr)
+{
+ T ptr = m_ptr;
+ m_ptr = optr;
+ if (ptr)
+ JSRelease(ptr);
+}
+
+template<typename T> template<typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(U* optr)
+{
+ if (optr)
+ JSRetain(optr);
+ T ptr = m_ptr;
+ m_ptr = optr;
+ if (ptr)
+ JSRelease(ptr);
+ return *this;
+}
+
+template<typename T> inline void JSRetainPtr<T>::swap(JSRetainPtr<T>& o)
+{
+ std::swap(m_ptr, o.m_ptr);
+}
+
+template<typename T> inline void swap(JSRetainPtr<T>& a, JSRetainPtr<T>& b)
+{
+ a.swap(b);
+}
+
+template<typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b)
+{
+ return a.get() == b.get();
+}
+
+template<typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, U* b)
+{
+ return a.get() == b;
+}
+
+template<typename T, typename U> inline bool operator==(T* a, const JSRetainPtr<U>& b)
+{
+ return a == b.get();
+}
+
+template<typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b)
+{
+ return a.get() != b.get();
+}
+
+template<typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, U* b)
+{
+ return a.get() != b;
+}
+
+template<typename T, typename U> inline bool operator!=(T* a, const JSRetainPtr<U>& b)
+{
+ return a != b.get();
+}
+
+
+#endif // JSRetainPtr_h
diff --git a/Source/JavaScriptCore/API/JSStringRef.cpp b/Source/JavaScriptCore/API/JSStringRef.cpp
new file mode 100644
index 0000000..ea31da6
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSStringRef.cpp
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2006, 2007 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 "JSStringRef.h"
+
+#include "InitializeThreading.h"
+#include "OpaqueJSString.h"
+#include <wtf/unicode/UTF8.h>
+
+using namespace JSC;
+using namespace WTF::Unicode;
+
+JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars)
+{
+ initializeThreading();
+ return OpaqueJSString::create(chars, numChars).leakRef();
+}
+
+JSStringRef JSStringCreateWithUTF8CString(const char* string)
+{
+ initializeThreading();
+ 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()).leakRef();
+ }
+
+ // Null string.
+ return OpaqueJSString::create().leakRef();
+}
+
+JSStringRef JSStringRetain(JSStringRef string)
+{
+ string->ref();
+ return string;
+}
+
+void JSStringRelease(JSStringRef string)
+{
+ string->deref();
+}
+
+size_t JSStringGetLength(JSStringRef string)
+{
+ return string->length();
+}
+
+const JSChar* JSStringGetCharactersPtr(JSStringRef string)
+{
+ return string->characters();
+}
+
+size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string)
+{
+ // Any UTF8 character > 3 bytes encodes as a UTF16 surrogate pair.
+ return string->length() * 3 + 1; // + 1 for terminating '\0'
+}
+
+size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize)
+{
+ 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;
+
+ return p - buffer;
+}
+
+bool JSStringIsEqual(JSStringRef a, JSStringRef b)
+{
+ unsigned len = a->length();
+ return len == b->length() && 0 == memcmp(a->characters(), b->characters(), len * sizeof(UChar));
+}
+
+bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b)
+{
+ JSStringRef bBuf = JSStringCreateWithUTF8CString(b);
+ bool result = JSStringIsEqual(a, bBuf);
+ JSStringRelease(bBuf);
+
+ return result;
+}
diff --git a/Source/JavaScriptCore/API/JSStringRef.h b/Source/JavaScriptCore/API/JSStringRef.h
new file mode 100644
index 0000000..c5c1544
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSStringRef.h
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2006 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 JSStringRef_h
+#define JSStringRef_h
+
+#include <JavaScriptCore/JSValueRef.h>
+
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+#include <stddef.h> /* for size_t */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if !defined(WIN32) && !defined(_WIN32) && !defined(__WINSCW__) \
+ && !((defined(__CC_ARM) || defined(__ARMCC__)) && !defined(__linux__)) /* RVCT */
+/*!
+@typedef JSChar
+@abstract A Unicode character.
+*/
+ typedef unsigned short JSChar;
+#else
+ typedef wchar_t JSChar;
+#endif
+
+/*!
+@function
+@abstract Creates a JavaScript string from a buffer of Unicode characters.
+@param chars The buffer of Unicode characters to copy into the new JSString.
+@param numChars The number of characters to copy from the buffer pointed to by chars.
+@result A JSString containing chars. Ownership follows the Create Rule.
+*/
+JS_EXPORT JSStringRef JSStringCreateWithCharacters(const JSChar* chars, size_t numChars);
+/*!
+@function
+@abstract Creates a JavaScript string from a null-terminated UTF8 string.
+@param string The null-terminated UTF8 string to copy into the new JSString.
+@result A JSString containing string. Ownership follows the Create Rule.
+*/
+JS_EXPORT JSStringRef JSStringCreateWithUTF8CString(const char* string);
+
+/*!
+@function
+@abstract Retains a JavaScript string.
+@param string The JSString to retain.
+@result A JSString that is the same as string.
+*/
+JS_EXPORT JSStringRef JSStringRetain(JSStringRef string);
+/*!
+@function
+@abstract Releases a JavaScript string.
+@param string The JSString to release.
+*/
+JS_EXPORT void JSStringRelease(JSStringRef string);
+
+/*!
+@function
+@abstract Returns the number of Unicode characters in a JavaScript string.
+@param string The JSString whose length (in Unicode characters) you want to know.
+@result The number of Unicode characters stored in string.
+*/
+JS_EXPORT size_t JSStringGetLength(JSStringRef string);
+/*!
+@function
+@abstract Returns a pointer to the Unicode character buffer that
+ serves as the backing store for a JavaScript string.
+@param string The JSString whose backing store you want to access.
+@result A pointer to the Unicode character buffer that serves as string's
+ backing store, which will be deallocated when string is deallocated.
+*/
+JS_EXPORT const JSChar* JSStringGetCharactersPtr(JSStringRef string);
+
+/*!
+@function
+@abstract Returns the maximum number of bytes a JavaScript string will
+ take up if converted into a null-terminated UTF8 string.
+@param string The JSString whose maximum converted size (in bytes) you
+ want to know.
+@result The maximum number of bytes that could be required to convert string into a
+ null-terminated UTF8 string. The number of bytes that the conversion actually ends
+ up requiring could be less than this, but never more.
+*/
+JS_EXPORT size_t JSStringGetMaximumUTF8CStringSize(JSStringRef string);
+/*!
+@function
+@abstract Converts a JavaScript string into a null-terminated UTF8 string,
+ and copies the result into an external byte buffer.
+@param string The source JSString.
+@param buffer The destination byte buffer into which to copy a null-terminated
+ UTF8 representation of string. On return, buffer contains a UTF8 string
+ representation of string. If bufferSize is too small, buffer will contain only
+ partial results. If buffer is not at least bufferSize bytes in size,
+ behavior is undefined.
+@param bufferSize The size of the external buffer in bytes.
+@result The number of bytes written into buffer (including the null-terminator byte).
+*/
+JS_EXPORT size_t JSStringGetUTF8CString(JSStringRef string, char* buffer, size_t bufferSize);
+
+/*!
+@function
+@abstract Tests whether two JavaScript strings match.
+@param a The first JSString to test.
+@param b The second JSString to test.
+@result true if the two strings match, otherwise false.
+*/
+JS_EXPORT bool JSStringIsEqual(JSStringRef a, JSStringRef b);
+/*!
+@function
+@abstract Tests whether a JavaScript string matches a null-terminated UTF8 string.
+@param a The JSString to test.
+@param b The null-terminated UTF8 string to test.
+@result true if the two strings match, otherwise false.
+*/
+JS_EXPORT bool JSStringIsEqualToUTF8CString(JSStringRef a, const char* b);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSStringRef_h */
diff --git a/Source/JavaScriptCore/API/JSStringRefBSTR.cpp b/Source/JavaScriptCore/API/JSStringRefBSTR.cpp
new file mode 100644
index 0000000..70f4254
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSStringRefBSTR.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2007 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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 "JSStringRefBSTR.h"
+
+#include "JSStringRef.h"
+
+JSStringRef JSStringCreateWithBSTR(BSTR string)
+{
+ return JSStringCreateWithCharacters(string ? string : L"", string ? SysStringLen(string) : 0);
+}
+
+BSTR JSStringCopyBSTR(const JSStringRef string)
+{
+ return SysAllocStringLen(JSStringGetCharactersPtr(string), JSStringGetLength(string));
+}
diff --git a/Source/JavaScriptCore/API/JSStringRefBSTR.h b/Source/JavaScriptCore/API/JSStringRefBSTR.h
new file mode 100644
index 0000000..59f19b7
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSStringRefBSTR.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2007 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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 JSStringRefBSTR_h
+#define JSStringRefBSTR_h
+
+#include "JSBase.h"
+
+#include <windows.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* COM convenience methods */
+
+/*!
+@function
+@abstract Creates a JavaScript string from a BSTR.
+@param string The BSTR to copy into the new JSString.
+@result A JSString containing string. Ownership follows the Create Rule.
+*/
+JS_EXPORT JSStringRef JSStringCreateWithBSTR(const BSTR string);
+
+/*!
+@function
+@abstract Creates a BSTR from a JavaScript string.
+@param string The JSString to copy into the new BSTR.
+@result A BSTR containing string. Ownership follows the Create Rule.
+*/
+JS_EXPORT BSTR JSStringCopyBSTR(const JSStringRef string);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSStringRefBSTR_h */
diff --git a/Source/JavaScriptCore/API/JSStringRefCF.cpp b/Source/JavaScriptCore/API/JSStringRefCF.cpp
new file mode 100644
index 0000000..e0961d0
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSStringRefCF.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2006, 2007 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.
+ */
+
+#include "config.h"
+#include "JSStringRefCF.h"
+
+#include "APICast.h"
+#include "InitializeThreading.h"
+#include "JSStringRef.h"
+#include "OpaqueJSString.h"
+#include <runtime/UString.h>
+#include <runtime/JSValue.h>
+#include <wtf/OwnArrayPtr.h>
+
+JSStringRef JSStringCreateWithCFString(CFStringRef string)
+{
+ JSC::initializeThreading();
+
+ // We cannot use CFIndex here since CFStringGetLength can return values larger than
+ // it can hold. (<rdar://problem/6806478>)
+ size_t length = CFStringGetLength(string);
+ 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).leakRef();
+ } else {
+ return OpaqueJSString::create(0, 0).leakRef();
+ }
+}
+
+CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string)
+{
+ return CFStringCreateWithCharacters(alloc, reinterpret_cast<const UniChar*>(string->characters()), string->length());
+}
diff --git a/Source/JavaScriptCore/API/JSStringRefCF.h b/Source/JavaScriptCore/API/JSStringRefCF.h
new file mode 100644
index 0000000..a424765
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSStringRefCF.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2006, 2007 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 JSStringRefCF_h
+#define JSStringRefCF_h
+
+#include "JSBase.h"
+#include <CoreFoundation/CoreFoundation.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* CFString convenience methods */
+
+/*!
+@function
+@abstract Creates a JavaScript string from a CFString.
+@discussion This function is optimized to take advantage of cases when
+ CFStringGetCharactersPtr returns a valid pointer.
+@param string The CFString to copy into the new JSString.
+@result A JSString containing string. Ownership follows the Create Rule.
+*/
+JS_EXPORT JSStringRef JSStringCreateWithCFString(CFStringRef string);
+/*!
+@function
+@abstract Creates a CFString from a JavaScript string.
+@param alloc The alloc parameter to pass to CFStringCreate.
+@param string The JSString to copy into the new CFString.
+@result A CFString containing string. Ownership follows the Create Rule.
+*/
+JS_EXPORT CFStringRef JSStringCopyCFString(CFAllocatorRef alloc, JSStringRef string);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSStringRefCF_h */
diff --git a/Source/JavaScriptCore/API/JSValueRef.cpp b/Source/JavaScriptCore/API/JSValueRef.cpp
new file mode 100644
index 0000000..faf4712
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSValueRef.cpp
@@ -0,0 +1,334 @@
+/*
+ * Copyright (C) 2006, 2007 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 "JSValueRef.h"
+
+#include "APICast.h"
+#include "APIShims.h"
+#include "JSCallbackObject.h"
+
+#include <runtime/JSGlobalObject.h>
+#include <runtime/JSONObject.h>
+#include <runtime/JSString.h>
+#include <runtime/LiteralParser.h>
+#include <runtime/Operations.h>
+#include <runtime/Protect.h>
+#include <runtime/UString.h>
+#include <runtime/JSValue.h>
+
+#include <wtf/Assertions.h>
+#include <wtf/text/StringHash.h>
+
+#include <algorithm> // for std::min
+
+using namespace JSC;
+
+::JSType JSValueGetType(JSContextRef ctx, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, 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;
+}
+
+bool JSValueIsUndefined(JSContextRef ctx, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+ return jsValue.isUndefined();
+}
+
+bool JSValueIsNull(JSContextRef ctx, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+ return jsValue.isNull();
+}
+
+bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+ return jsValue.isBoolean();
+}
+
+bool JSValueIsNumber(JSContextRef ctx, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+ return jsValue.isNumber();
+}
+
+bool JSValueIsString(JSContextRef ctx, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+ return jsValue.isString();
+}
+
+bool JSValueIsObject(JSContextRef ctx, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+ return jsValue.isObject();
+}
+
+bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+
+ if (JSObject* o = jsValue.getObject()) {
+ if (o->inherits(&JSCallbackObject<JSGlobalObject>::info))
+ return static_cast<JSCallbackObject<JSGlobalObject>*>(o)->inherits(jsClass);
+ else if (o->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info))
+ return static_cast<JSCallbackObject<JSObjectWithGlobalObject>*>(o)->inherits(jsClass);
+ }
+ return false;
+}
+
+bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsA = toJS(exec, a);
+ JSValue jsB = toJS(exec, b);
+
+ bool result = JSValue::equal(exec, jsA, jsB); // false if an exception is thrown
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ }
+ return result;
+}
+
+bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsA = toJS(exec, a);
+ JSValue jsB = toJS(exec, b);
+
+ return JSValue::strictEqual(exec, jsA, jsB);
+}
+
+bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+
+ JSObject* jsConstructor = toJS(constructor);
+ if (!jsConstructor->structure()->typeInfo().implementsHasInstance())
+ return false;
+ 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, exec->exception());
+ exec->clearException();
+ }
+ return result;
+}
+
+JSValueRef JSValueMakeUndefined(JSContextRef ctx)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ return toRef(exec, jsUndefined());
+}
+
+JSValueRef JSValueMakeNull(JSContextRef ctx)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ return toRef(exec, jsNull());
+}
+
+JSValueRef JSValueMakeBoolean(JSContextRef ctx, bool value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ return toRef(exec, jsBoolean(value));
+}
+
+JSValueRef JSValueMakeNumber(JSContextRef ctx, double value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ // Our JSValue representation relies on a standard bit pattern for NaN. NaNs
+ // generated internally to JavaScriptCore naturally have that representation,
+ // but an external NaN might not.
+ if (isnan(value))
+ value = NaN;
+
+ return toRef(exec, jsNumber(value));
+}
+
+JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ return toRef(exec, jsString(exec, string->ustring()));
+}
+
+JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+ LiteralParser parser(exec, string->ustring(), LiteralParser::StrictJSON);
+ return toRef(exec, parser.tryLiteralParse());
+}
+
+JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef apiValue, unsigned indent, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+ JSValue value = toJS(exec, apiValue);
+ UString result = JSONStringify(exec, value, indent);
+ if (exception)
+ *exception = 0;
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ return 0;
+ }
+ return OpaqueJSString::create(result).leakRef();
+}
+
+bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+ return jsValue.toBoolean(exec);
+}
+
+double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+
+ double number = jsValue.toNumber(exec);
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ number = NaN;
+ }
+ return number;
+}
+
+JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+
+ RefPtr<OpaqueJSString> stringRef(OpaqueJSString::create(jsValue.toString(exec)));
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ stringRef.clear();
+ }
+ return stringRef.release().leakRef();
+}
+
+JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJS(exec, value);
+
+ JSObjectRef objectRef = toRef(jsValue.toObject(exec));
+ if (exec->hadException()) {
+ if (exception)
+ *exception = toRef(exec, exec->exception());
+ exec->clearException();
+ objectRef = 0;
+ }
+ return objectRef;
+}
+
+void JSValueProtect(JSContextRef ctx, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJSForGC(exec, value);
+ gcProtect(jsValue);
+}
+
+void JSValueUnprotect(JSContextRef ctx, JSValueRef value)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+
+ JSValue jsValue = toJSForGC(exec, value);
+ gcUnprotect(jsValue);
+}
diff --git a/Source/JavaScriptCore/API/JSValueRef.h b/Source/JavaScriptCore/API/JSValueRef.h
new file mode 100644
index 0000000..4186db8
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSValueRef.h
@@ -0,0 +1,301 @@
+/*
+ * Copyright (C) 2006 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 JSValueRef_h
+#define JSValueRef_h
+
+#include <JavaScriptCore/JSBase.h>
+#include <JavaScriptCore/WebKitAvailability.h>
+
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+
+/*!
+@enum JSType
+@abstract A constant identifying the type of a JSValue.
+@constant kJSTypeUndefined The unique undefined value.
+@constant kJSTypeNull The unique null value.
+@constant kJSTypeBoolean A primitive boolean value, one of true or false.
+@constant kJSTypeNumber A primitive number value.
+@constant kJSTypeString A primitive string value.
+@constant kJSTypeObject An object value (meaning that this JSValueRef is a JSObjectRef).
+*/
+typedef enum {
+ kJSTypeUndefined,
+ kJSTypeNull,
+ kJSTypeBoolean,
+ kJSTypeNumber,
+ kJSTypeString,
+ kJSTypeObject
+} JSType;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*!
+@function
+@abstract Returns a JavaScript value's type.
+@param ctx The execution context to use.
+@param value The JSValue whose type you want to obtain.
+@result A value of type JSType that identifies value's type.
+*/
+JS_EXPORT JSType JSValueGetType(JSContextRef ctx, JSValueRef value);
+
+/*!
+@function
+@abstract Tests whether a JavaScript value's type is the undefined type.
+@param ctx The execution context to use.
+@param value The JSValue to test.
+@result true if value's type is the undefined type, otherwise false.
+*/
+JS_EXPORT bool JSValueIsUndefined(JSContextRef ctx, JSValueRef value);
+
+/*!
+@function
+@abstract Tests whether a JavaScript value's type is the null type.
+@param ctx The execution context to use.
+@param value The JSValue to test.
+@result true if value's type is the null type, otherwise false.
+*/
+JS_EXPORT bool JSValueIsNull(JSContextRef ctx, JSValueRef value);
+
+/*!
+@function
+@abstract Tests whether a JavaScript value's type is the boolean type.
+@param ctx The execution context to use.
+@param value The JSValue to test.
+@result true if value's type is the boolean type, otherwise false.
+*/
+JS_EXPORT bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value);
+
+/*!
+@function
+@abstract Tests whether a JavaScript value's type is the number type.
+@param ctx The execution context to use.
+@param value The JSValue to test.
+@result true if value's type is the number type, otherwise false.
+*/
+JS_EXPORT bool JSValueIsNumber(JSContextRef ctx, JSValueRef value);
+
+/*!
+@function
+@abstract Tests whether a JavaScript value's type is the string type.
+@param ctx The execution context to use.
+@param value The JSValue to test.
+@result true if value's type is the string type, otherwise false.
+*/
+JS_EXPORT bool JSValueIsString(JSContextRef ctx, JSValueRef value);
+
+/*!
+@function
+@abstract Tests whether a JavaScript value's type is the object type.
+@param ctx The execution context to use.
+@param value The JSValue to test.
+@result true if value's type is the object type, otherwise false.
+*/
+JS_EXPORT bool JSValueIsObject(JSContextRef ctx, JSValueRef value);
+
+/*!
+@function
+@abstract Tests whether a JavaScript value is an object with a given class in its class chain.
+@param ctx The execution context to use.
+@param value The JSValue to test.
+@param jsClass The JSClass to test against.
+@result true if value is an object and has jsClass in its class chain, otherwise false.
+*/
+JS_EXPORT bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass);
+
+/* Comparing values */
+
+/*!
+@function
+@abstract Tests whether two JavaScript values are equal, as compared by the JS == operator.
+@param ctx The execution context to use.
+@param a The first value to test.
+@param b The second value to test.
+@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 true if the two values are equal, false if they are not equal or an exception is thrown.
+*/
+JS_EXPORT bool JSValueIsEqual(JSContextRef ctx, JSValueRef a, JSValueRef b, JSValueRef* exception);
+
+/*!
+@function
+@abstract Tests whether two JavaScript values are strict equal, as compared by the JS === operator.
+@param ctx The execution context to use.
+@param a The first value to test.
+@param b The second value to test.
+@result true if the two values are strict equal, otherwise false.
+*/
+JS_EXPORT bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b);
+
+/*!
+@function
+@abstract Tests whether a JavaScript value is an object constructed by a given constructor, as compared by the JS instanceof operator.
+@param ctx The execution context to use.
+@param value The JSValue to test.
+@param constructor The constructor to test against.
+@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 true if value is an object constructed by constructor, as compared by the JS instanceof operator, otherwise false.
+*/
+JS_EXPORT bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception);
+
+/* Creating values */
+
+/*!
+@function
+@abstract Creates a JavaScript value of the undefined type.
+@param ctx The execution context to use.
+@result The unique undefined value.
+*/
+JS_EXPORT JSValueRef JSValueMakeUndefined(JSContextRef ctx);
+
+/*!
+@function
+@abstract Creates a JavaScript value of the null type.
+@param ctx The execution context to use.
+@result The unique null value.
+*/
+JS_EXPORT JSValueRef JSValueMakeNull(JSContextRef ctx);
+
+/*!
+@function
+@abstract Creates a JavaScript value of the boolean type.
+@param ctx The execution context to use.
+@param boolean The bool to assign to the newly created JSValue.
+@result A JSValue of the boolean type, representing the value of boolean.
+*/
+JS_EXPORT JSValueRef JSValueMakeBoolean(JSContextRef ctx, bool boolean);
+
+/*!
+@function
+@abstract Creates a JavaScript value of the number type.
+@param ctx The execution context to use.
+@param number The double to assign to the newly created JSValue.
+@result A JSValue of the number type, representing the value of number.
+*/
+JS_EXPORT JSValueRef JSValueMakeNumber(JSContextRef ctx, double number);
+
+/*!
+@function
+@abstract Creates a JavaScript value of the string type.
+@param ctx The execution context to use.
+@param string The JSString to assign to the newly created JSValue. The
+ newly created JSValue retains string, and releases it upon garbage collection.
+@result A JSValue of the string type, representing the value of string.
+*/
+JS_EXPORT JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string);
+
+/* Converting to and from JSON formatted strings */
+
+/*!
+ @function
+ @abstract Creates a JavaScript value from a JSON formatted string.
+ @param ctx The execution context to use.
+ @param string The JSString containing the JSON string to be parsed.
+ @result A JSValue containing the parsed value, or NULL if the input is invalid.
+ */
+JS_EXPORT JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string) AVAILABLE_AFTER_WEBKIT_VERSION_4_0;
+
+/*!
+ @function
+ @abstract Creates a JavaScript string containing the JSON serialized representation of a JS value.
+ @param ctx The execution context to use.
+ @param value The value to serialize.
+ @param indent The number of spaces to indent when nesting. If 0, the resulting JSON will not contains newlines. The size of the indent is clamped to 10 spaces.
+ @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 JSString with the result of serialization, or NULL if an exception is thrown.
+ */
+JS_EXPORT JSStringRef JSValueCreateJSONString(JSContextRef ctx, JSValueRef value, unsigned indent, JSValueRef* exception) AVAILABLE_AFTER_WEBKIT_VERSION_4_0;
+
+/* Converting to primitive values */
+
+/*!
+@function
+@abstract Converts a JavaScript value to boolean and returns the resulting boolean.
+@param ctx The execution context to use.
+@param value The JSValue to convert.
+@result The boolean result of conversion.
+*/
+JS_EXPORT bool JSValueToBoolean(JSContextRef ctx, JSValueRef value);
+
+/*!
+@function
+@abstract Converts a JavaScript value to number and returns the resulting number.
+@param ctx The execution context to use.
+@param value The JSValue to convert.
+@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 The numeric result of conversion, or NaN if an exception is thrown.
+*/
+JS_EXPORT double JSValueToNumber(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
+
+/*!
+@function
+@abstract Converts a JavaScript value to string and copies the result into a JavaScript string.
+@param ctx The execution context to use.
+@param value The JSValue to convert.
+@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 JSString with the result of conversion, or NULL if an exception is thrown. Ownership follows the Create Rule.
+*/
+JS_EXPORT JSStringRef JSValueToStringCopy(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
+
+/*!
+@function
+@abstract Converts a JavaScript value to object and returns the resulting object.
+@param ctx The execution context to use.
+@param value The JSValue to convert.
+@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 The JSObject result of conversion, or NULL if an exception is thrown.
+*/
+JS_EXPORT JSObjectRef JSValueToObject(JSContextRef ctx, JSValueRef value, JSValueRef* exception);
+
+/* Garbage collection */
+/*!
+@function
+@abstract Protects a JavaScript value from garbage collection.
+@param ctx The execution context to use.
+@param value The JSValue to protect.
+@discussion Use this method when you want to store a JSValue in a global or on the heap, where the garbage collector will not be able to discover your reference to it.
+
+A value may be protected multiple times and must be unprotected an equal number of times before becoming eligible for garbage collection.
+*/
+JS_EXPORT void JSValueProtect(JSContextRef ctx, JSValueRef value);
+
+/*!
+@function
+@abstract Unprotects a JavaScript value from garbage collection.
+@param ctx The execution context to use.
+@param value The JSValue to unprotect.
+@discussion A value may be protected multiple times and must be unprotected an
+ equal number of times before becoming eligible for garbage collection.
+*/
+JS_EXPORT void JSValueUnprotect(JSContextRef ctx, JSValueRef value);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* JSValueRef_h */
diff --git a/Source/JavaScriptCore/API/JSWeakObjectMapRefInternal.h b/Source/JavaScriptCore/API/JSWeakObjectMapRefInternal.h
new file mode 100644
index 0000000..64e1f4d
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSWeakObjectMapRefInternal.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 ITS 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 JSWeakObjectMapRefInternal_h
+#define JSWeakObjectMapRefInternal_h
+
+#include "WeakGCMap.h"
+#include <wtf/RefCounted.h>
+
+namespace JSC {
+
+class JSObject;
+
+}
+
+typedef void (*JSWeakMapDestroyedCallback)(struct OpaqueJSWeakObjectMap*, void*);
+
+typedef JSC::WeakGCMap<void*, JSC::JSObject*> WeakMapType;
+
+struct OpaqueJSWeakObjectMap : public RefCounted<OpaqueJSWeakObjectMap> {
+public:
+ static PassRefPtr<OpaqueJSWeakObjectMap> create(void* data, JSWeakMapDestroyedCallback callback)
+ {
+ return adoptRef(new OpaqueJSWeakObjectMap(data, callback));
+ }
+
+ WeakMapType& map() { return m_map; }
+
+ ~OpaqueJSWeakObjectMap()
+ {
+ m_callback(this, m_data);
+ }
+
+private:
+ OpaqueJSWeakObjectMap(void* data, JSWeakMapDestroyedCallback callback)
+ : m_data(data)
+ , m_callback(callback)
+ {
+ }
+ WeakMapType m_map;
+ void* m_data;
+ JSWeakMapDestroyedCallback m_callback;
+};
+
+
+#endif // JSWeakObjectMapInternal_h
diff --git a/Source/JavaScriptCore/API/JSWeakObjectMapRefPrivate.cpp b/Source/JavaScriptCore/API/JSWeakObjectMapRefPrivate.cpp
new file mode 100644
index 0000000..8182075
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSWeakObjectMapRefPrivate.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 ITS 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 "JSWeakObjectMapRefPrivate.h"
+
+#include "APICast.h"
+#include "APIShims.h"
+#include "JSCallbackObject.h"
+#include "JSValue.h"
+#include "JSWeakObjectMapRefInternal.h"
+#include <wtf/HashMap.h>
+#include <wtf/text/StringHash.h>
+
+using namespace WTF;
+using namespace JSC;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+JSWeakObjectMapRef JSWeakObjectMapCreate(JSContextRef context, void* privateData, JSWeakMapDestroyedCallback callback)
+{
+ ExecState* exec = toJS(context);
+ APIEntryShim entryShim(exec);
+ RefPtr<OpaqueJSWeakObjectMap> map = OpaqueJSWeakObjectMap::create(privateData, callback);
+ exec->lexicalGlobalObject()->registerWeakMap(map.get());
+ return map.get();
+}
+
+void JSWeakObjectMapSet(JSContextRef ctx, JSWeakObjectMapRef map, void* key, JSObjectRef object)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+ JSObject* obj = toJS(object);
+ if (!obj)
+ return;
+ ASSERT(obj->inherits(&JSCallbackObject<JSGlobalObject>::info) || obj->inherits(&JSCallbackObject<JSObjectWithGlobalObject>::info));
+ map->map().set(key, obj);
+}
+
+JSObjectRef JSWeakObjectMapGet(JSContextRef ctx, JSWeakObjectMapRef map, void* key)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+ return toRef(static_cast<JSObject*>(map->map().get(key)));
+}
+
+bool JSWeakObjectMapClear(JSContextRef ctx, JSWeakObjectMapRef map, void* key, JSObjectRef object)
+{
+ ExecState* exec = toJS(ctx);
+ APIEntryShim entryShim(exec);
+ JSObject* obj = toJS(object);
+ if (map->map().uncheckedRemove(key, obj))
+ return true;
+ return false;
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/Source/JavaScriptCore/API/JSWeakObjectMapRefPrivate.h b/Source/JavaScriptCore/API/JSWeakObjectMapRefPrivate.h
new file mode 100644
index 0000000..d36111c
--- /dev/null
+++ b/Source/JavaScriptCore/API/JSWeakObjectMapRefPrivate.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2010 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. AND ITS CONTRIBUTORS ``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 ITS 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 JSWeakObjectMapRefPrivate_h
+#define JSWeakObjectMapRefPrivate_h
+
+#include <JavaScriptCore/JSContextRef.h>
+#include <JavaScriptCore/JSValueRef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*! @typedef JSWeakObjectMapRef A weak map for storing JSObjectRefs */
+typedef struct OpaqueJSWeakObjectMap* JSWeakObjectMapRef;
+
+/*!
+ @typedef JSWeakMapDestroyedCallback
+ @abstract The callback invoked when a JSWeakObjectMapRef is being destroyed.
+ @param map The map that is being destroyed.
+ @param data The private data (if any) that was associated with the map instance.
+ */
+typedef void (*JSWeakMapDestroyedCallback)(JSWeakObjectMapRef map, void* data);
+
+/*!
+ @function
+ @abstract Creates a weak value map that can be used to reference user defined objects without preventing them from being collected.
+ @param ctx The execution context to use.
+ @param data A void* to set as the map's private data. Pass NULL to specify no private data.
+ @param destructor A function to call when the weak map is destroyed.
+ @result A JSWeakObjectMapRef bound to the given context, data and destructor.
+ @discussion The JSWeakObjectMapRef can be used as a storage mechanism to hold custom JS objects without forcing those objects to
+ remain live as JSValueProtect would. Any objects that are intended to be stored in a weak map must be user defined objects that
+ remove themselves from the map in their finalizer.
+ */
+JS_EXPORT JSWeakObjectMapRef JSWeakObjectMapCreate(JSContextRef ctx, void* data, JSWeakMapDestroyedCallback destructor);
+
+/*!
+ @function
+ @abstract Associates a JSObjectRef with the given key in a JSWeakObjectMap.
+ @param ctx The execution context to use.
+ @param map The map to operate on.
+ @param key The key to associate a weak reference with.
+ @param object The user defined object to associate with the key.
+ */
+JS_EXPORT void JSWeakObjectMapSet(JSContextRef ctx, JSWeakObjectMapRef map, void* key, JSObjectRef);
+
+/*!
+ @function
+ @abstract Retrieves the JSObjectRef associated with a key.
+ @param ctx The execution context to use.
+ @param map The map to query.
+ @param key The key to search for.
+ @result Either the live object associated with the provided key, or NULL.
+ */
+JS_EXPORT JSObjectRef JSWeakObjectMapGet(JSContextRef ctx, JSWeakObjectMapRef map, void* key);
+
+/*!
+ @function
+ @abstract Clears the association between a key and an object in a JSWeakObjectMapRef
+ @param ctx The execution context to use.
+ @param map The map to clear the key association from.
+ @param key The key to use.
+ @param object The old object value.
+ @result Returns true if the key/object association was present in map, and has been removed.
+ */
+JS_EXPORT bool JSWeakObjectMapClear(JSContextRef ctx, JSWeakObjectMapRef map, void* key, JSObjectRef object);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // JSWeakObjectMapPrivate_h
diff --git a/Source/JavaScriptCore/API/JavaScript.h b/Source/JavaScriptCore/API/JavaScript.h
new file mode 100644
index 0000000..f8d92d8
--- /dev/null
+++ b/Source/JavaScriptCore/API/JavaScript.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2006 Apple Inc. All rights reserved.
+ * Copyright (C) 2008 Alp Toker <alp@atoker.com>
+ *
+ * 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 JavaScript_h
+#define JavaScript_h
+
+#include <JavaScriptCore/JSBase.h>
+#include <JavaScriptCore/JSContextRef.h>
+#include <JavaScriptCore/JSStringRef.h>
+#include <JavaScriptCore/JSObjectRef.h>
+#include <JavaScriptCore/JSValueRef.h>
+
+#endif /* JavaScript_h */
diff --git a/Source/JavaScriptCore/API/JavaScriptCore.h b/Source/JavaScriptCore/API/JavaScriptCore.h
new file mode 100644
index 0000000..87d6018
--- /dev/null
+++ b/Source/JavaScriptCore/API/JavaScriptCore.h
@@ -0,0 +1,32 @@
+/*
+ * 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
+ * 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 JavaScriptCore_h
+#define JavaScriptCore_h
+
+#include <JavaScriptCore/JavaScript.h>
+#include <JavaScriptCore/JSStringRefCF.h>
+
+#endif /* JavaScriptCore_h */
diff --git a/Source/JavaScriptCore/API/OpaqueJSString.cpp b/Source/JavaScriptCore/API/OpaqueJSString.cpp
new file mode 100644
index 0000000..9a116e6
--- /dev/null
+++ b/Source/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 <interpreter/CallFrame.h>
+#include <runtime/JSGlobalObject.h>
+#include <runtime/Identifier.h>
+
+using namespace JSC;
+
+PassRefPtr<OpaqueJSString> OpaqueJSString::create(const UString& ustring)
+{
+ if (!ustring.isNull())
+ return adoptRef(new OpaqueJSString(ustring.characters(), ustring.length()));
+ return 0;
+}
+
+UString OpaqueJSString::ustring() const
+{
+ if (this && m_characters)
+ return UString(m_characters, m_length);
+ return UString();
+}
+
+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/Source/JavaScriptCore/API/OpaqueJSString.h b/Source/JavaScriptCore/API/OpaqueJSString.h
new file mode 100644
index 0000000..473c815
--- /dev/null
+++ b/Source/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 <runtime/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/Source/JavaScriptCore/API/WebKitAvailability.h b/Source/JavaScriptCore/API/WebKitAvailability.h
new file mode 100644
index 0000000..0e4f091
--- /dev/null
+++ b/Source/JavaScriptCore/API/WebKitAvailability.h
@@ -0,0 +1,904 @@
+/*
+ * Copyright (C) 2008, 2009, 2010 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_4_0 0x0400
+#define WEBKIT_VERSION_LATEST 0x9999
+
+#ifdef __APPLE__
+#include <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
+ #elif !defined(MAC_OS_X_VERSION_10_7) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_7
+ /* WebKit 4.0 is the version that shipped on Mac OS X 10.6. */
+ #define WEBKIT_VERSION_MIN_REQUIRED WEBKIT_VERSION_4_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_IN_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 4.0
+ */
+#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_4_0
+ #define AVAILABLE_IN_WEBKIT_VERSION_4_0 UNAVAILABLE_ATTRIBUTE
+#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_4_0
+ #define AVAILABLE_IN_WEBKIT_VERSION_4_0 WEAK_IMPORT_ATTRIBUTE
+#else
+ #define AVAILABLE_IN_WEBKIT_VERSION_4_0
+#endif
+
+/*
+ * AVAILABLE_IN_WEBKIT_VERSION_4_0_BUT_DEPRECATED
+ *
+ * Used on declarations introduced in WebKit 4.0,
+ * and deprecated in WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_4_0
+ #define AVAILABLE_IN_WEBKIT_VERSION_4_0_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_IN_WEBKIT_VERSION_4_0_BUT_DEPRECATED AVAILABLE_IN_WEBKIT_VERSION_4_0
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 1.0,
+ * but later deprecated in WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_4_0
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 1.1,
+ * but later deprecated in WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_4_0
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 1.2,
+ * but later deprecated in WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_4_0
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 1.3,
+ * but later deprecated in WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_4_0
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 2.0,
+ * but later deprecated in WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_4_0
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 3.0,
+ * but later deprecated in WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_4_0
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 3.1,
+ * but later deprecated in WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_4_0
+ #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER
+#endif
+
+/*
+ * DEPRECATED_IN_WEBKIT_VERSION_4_0
+ *
+ * Used on types deprecated in WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_4_0
+ #define DEPRECATED_IN_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define DEPRECATED_IN_WEBKIT_VERSION_4_0
+#endif
+
+
+
+
+
+
+/*
+ * AVAILABLE_AFTER_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced after WebKit 4.0
+ */
+#if WEBKIT_VERSION_MAX_ALLOWED < WEBKIT_VERSION_LATEST
+ #define AVAILABLE_AFTER_WEBKIT_VERSION_4_0 UNAVAILABLE_ATTRIBUTE
+#elif WEBKIT_VERSION_MIN_REQUIRED < WEBKIT_VERSION_LATEST
+ #define AVAILABLE_AFTER_WEBKIT_VERSION_4_0 WEAK_IMPORT_ATTRIBUTE
+#else
+ #define AVAILABLE_AFTER_WEBKIT_VERSION_4_0
+#endif
+
+/*
+ * AVAILABLE_AFTER_WEBKIT_VERSION_4_0_BUT_DEPRECATED
+ *
+ * Used on declarations introduced after WebKit 4.0,
+ * and deprecated after WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_AFTER_WEBKIT_VERSION_4_0_BUT_DEPRECATED DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_AFTER_WEBKIT_VERSION_4_0_BUT_DEPRECATED AVAILABLE_AFTER_WEBKIT_VERSION_4_0
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 1.0,
+ * but later deprecated after WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_1_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 1.1,
+ * but later deprecated after WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_1_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 1.2,
+ * but later deprecated after WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_1_2_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 1.3,
+ * but later deprecated after WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 2.0,
+ * but later deprecated after WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_2_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 3.0,
+ * but later deprecated after WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 3.1,
+ * but later deprecated after WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_3_1_AND_LATER
+#endif
+
+/*
+ * AVAILABLE_WEBKIT_VERSION_4_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0
+ *
+ * Used on declarations introduced in WebKit 4.0
+ * but later deprecated after WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define AVAILABLE_WEBKIT_VERSION_4_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define AVAILABLE_WEBKIT_VERSION_4_0_AND_LATER_BUT_DEPRECATED_AFTER_WEBKIT_VERSION_4_0 AVAILABLE_WEBKIT_VERSION_4_0_AND_LATER
+#endif
+
+/*
+ * DEPRECATED_AFTER_WEBKIT_VERSION_4_0
+ *
+ * Used on types deprecated after WebKit 4.0
+ */
+#if WEBKIT_VERSION_MIN_REQUIRED >= WEBKIT_VERSION_LATEST
+ #define DEPRECATED_AFTER_WEBKIT_VERSION_4_0 DEPRECATED_ATTRIBUTE
+#else
+ #define DEPRECATED_AFTER_WEBKIT_VERSION_4_0
+#endif
+
+
+#endif /* __WebKitAvailability__ */
diff --git a/Source/JavaScriptCore/API/tests/JSNode.c b/Source/JavaScriptCore/API/tests/JSNode.c
new file mode 100644
index 0000000..d9ac0a9
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/JSNode.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#include "JSNode.h"
+#include "JSNodeList.h"
+#include "JSObjectRef.h"
+#include "JSStringRef.h"
+#include "JSValueRef.h"
+#include "Node.h"
+#include "NodeList.h"
+#include "UnusedParam.h"
+#include <wtf/Assertions.h>
+
+static JSValueRef JSNode_appendChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(function);
+
+ /* 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);
+ JSStringRelease(message);
+ } else if (argumentCount < 1 || !JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
+ JSStringRef message = JSStringCreateWithUTF8CString("TypeError: first argument to appendChild must be a node");
+ *exception = JSValueMakeString(context, message);
+ JSStringRelease(message);
+ } else {
+ Node* node = JSObjectGetPrivate(thisObject);
+ Node* child = JSObjectGetPrivate(JSValueToObject(context, arguments[0], NULL));
+
+ Node_appendChild(node, child);
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+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 */
+ if (argumentCount > 0) {
+ if (JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
+ if (JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
+ Node* node = JSObjectGetPrivate(thisObject);
+ Node* child = JSObjectGetPrivate(JSValueToObject(context, arguments[0], exception));
+
+ Node_removeChild(node, child);
+ }
+ }
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+static JSValueRef JSNode_replaceChild(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(function);
+
+ if (argumentCount > 1) {
+ if (JSValueIsObjectOfClass(context, thisObject, JSNode_class(context))) {
+ if (JSValueIsObjectOfClass(context, arguments[0], JSNode_class(context))) {
+ if (JSValueIsObjectOfClass(context, arguments[1], JSNode_class(context))) {
+ Node* node = JSObjectGetPrivate(thisObject);
+ Node* newChild = JSObjectGetPrivate(JSValueToObject(context, arguments[0], exception));
+ Node* oldChild = JSObjectGetPrivate(JSValueToObject(context, arguments[1], exception));
+
+ Node_replaceChild(node, newChild, oldChild);
+ }
+ }
+ }
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+static JSStaticFunction JSNode_staticFunctions[] = {
+ { "appendChild", JSNode_appendChild, kJSPropertyAttributeDontDelete },
+ { "removeChild", JSNode_removeChild, kJSPropertyAttributeDontDelete },
+ { "replaceChild", JSNode_replaceChild, kJSPropertyAttributeDontDelete },
+ { 0, 0, 0 }
+};
+
+static JSValueRef JSNode_getNodeType(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+ UNUSED_PARAM(propertyName);
+ UNUSED_PARAM(exception);
+
+ Node* node = JSObjectGetPrivate(object);
+ if (node) {
+ JSStringRef nodeType = JSStringCreateWithUTF8CString(node->nodeType);
+ JSValueRef value = JSValueMakeString(context, nodeType);
+ JSStringRelease(nodeType);
+ return value;
+ }
+
+ return NULL;
+}
+
+static JSValueRef JSNode_getChildNodes(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
+{
+ UNUSED_PARAM(propertyName);
+ UNUSED_PARAM(exception);
+
+ Node* node = JSObjectGetPrivate(thisObject);
+ ASSERT(node);
+ return JSNodeList_new(context, NodeList_new(node));
+}
+
+static JSValueRef JSNode_getFirstChild(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(propertyName);
+ UNUSED_PARAM(exception);
+
+ return JSValueMakeUndefined(context);
+}
+
+static JSStaticValue JSNode_staticValues[] = {
+ { "nodeType", JSNode_getNodeType, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
+ { "childNodes", JSNode_getChildNodes, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
+ { "firstChild", JSNode_getFirstChild, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
+ { 0, 0, 0, 0 }
+};
+
+static void JSNode_initialize(JSContextRef context, JSObjectRef object)
+{
+ UNUSED_PARAM(context);
+
+ Node* node = JSObjectGetPrivate(object);
+ ASSERT(node);
+
+ Node_ref(node);
+}
+
+static void JSNode_finalize(JSObjectRef object)
+{
+ Node* node = JSObjectGetPrivate(object);
+ ASSERT(node);
+
+ Node_deref(node);
+}
+
+JSClassRef JSNode_class(JSContextRef context)
+{
+ UNUSED_PARAM(context);
+
+ static JSClassRef jsClass;
+ if (!jsClass) {
+ JSClassDefinition definition = kJSClassDefinitionEmpty;
+ definition.staticValues = JSNode_staticValues;
+ definition.staticFunctions = JSNode_staticFunctions;
+ definition.initialize = JSNode_initialize;
+ definition.finalize = JSNode_finalize;
+
+ jsClass = JSClassCreate(&definition);
+ }
+ return jsClass;
+}
+
+JSObjectRef JSNode_new(JSContextRef context, Node* node)
+{
+ return JSObjectMake(context, JSNode_class(context), node);
+}
+
+JSObjectRef JSNode_construct(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(argumentCount);
+ UNUSED_PARAM(arguments);
+ UNUSED_PARAM(exception);
+
+ return JSNode_new(context, Node_new());
+}
diff --git a/Source/JavaScriptCore/API/tests/JSNode.h b/Source/JavaScriptCore/API/tests/JSNode.h
new file mode 100644
index 0000000..7725733
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/JSNode.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2006 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 JSNode_h
+#define JSNode_h
+
+#include "JSBase.h"
+#include "Node.h"
+#include <stddef.h>
+
+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 */
diff --git a/Source/JavaScriptCore/API/tests/JSNodeList.c b/Source/JavaScriptCore/API/tests/JSNodeList.c
new file mode 100644
index 0000000..bc4a8ad
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/JSNodeList.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#include "JSNode.h"
+#include "JSNodeList.h"
+#include "JSObjectRef.h"
+#include "JSValueRef.h"
+#include "UnusedParam.h"
+#include <wtf/Assertions.h>
+
+static JSValueRef JSNodeList_item(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(object);
+
+ if (argumentCount > 0) {
+ NodeList* nodeList = JSObjectGetPrivate(thisObject);
+ ASSERT(nodeList);
+ Node* node = NodeList_item(nodeList, (unsigned)JSValueToNumber(context, arguments[0], exception));
+ if (node)
+ return JSNode_new(context, node);
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+static JSStaticFunction JSNodeList_staticFunctions[] = {
+ { "item", JSNodeList_item, kJSPropertyAttributeDontDelete },
+ { 0, 0, 0 }
+};
+
+static JSValueRef JSNodeList_length(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
+{
+ UNUSED_PARAM(propertyName);
+ UNUSED_PARAM(exception);
+
+ NodeList* nodeList = JSObjectGetPrivate(thisObject);
+ ASSERT(nodeList);
+ return JSValueMakeNumber(context, NodeList_length(nodeList));
+}
+
+static JSStaticValue JSNodeList_staticValues[] = {
+ { "length", JSNodeList_length, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete },
+ { 0, 0, 0, 0 }
+};
+
+static JSValueRef JSNodeList_getProperty(JSContextRef context, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
+{
+ NodeList* nodeList = JSObjectGetPrivate(thisObject);
+ ASSERT(nodeList);
+ double index = JSValueToNumber(context, JSValueMakeString(context, propertyName), exception);
+ unsigned uindex = (unsigned)index;
+ if (uindex == index) { /* false for NaN */
+ Node* node = NodeList_item(nodeList, uindex);
+ if (node)
+ return JSNode_new(context, node);
+ }
+
+ return NULL;
+}
+
+static void JSNodeList_initialize(JSContextRef context, JSObjectRef thisObject)
+{
+ UNUSED_PARAM(context);
+
+ NodeList* nodeList = JSObjectGetPrivate(thisObject);
+ ASSERT(nodeList);
+
+ NodeList_ref(nodeList);
+}
+
+static void JSNodeList_finalize(JSObjectRef thisObject)
+{
+ NodeList* nodeList = JSObjectGetPrivate(thisObject);
+ ASSERT(nodeList);
+
+ NodeList_deref(nodeList);
+}
+
+static JSClassRef JSNodeList_class(JSContextRef context)
+{
+ UNUSED_PARAM(context);
+
+ static JSClassRef jsClass;
+ if (!jsClass) {
+ JSClassDefinition definition = kJSClassDefinitionEmpty;
+ definition.staticValues = JSNodeList_staticValues;
+ definition.staticFunctions = JSNodeList_staticFunctions;
+ definition.getProperty = JSNodeList_getProperty;
+ definition.initialize = JSNodeList_initialize;
+ definition.finalize = JSNodeList_finalize;
+
+ jsClass = JSClassCreate(&definition);
+ }
+
+ return jsClass;
+}
+
+JSObjectRef JSNodeList_new(JSContextRef context, NodeList* nodeList)
+{
+ return JSObjectMake(context, JSNodeList_class(context), nodeList);
+}
diff --git a/Source/JavaScriptCore/API/tests/JSNodeList.h b/Source/JavaScriptCore/API/tests/JSNodeList.h
new file mode 100644
index 0000000..f930914
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/JSNodeList.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2006 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 JSNodeList_h
+#define JSNodeList_h
+
+#include "JSBase.h"
+#include "NodeList.h"
+
+extern JSObjectRef JSNodeList_new(JSContextRef, NodeList*);
+
+#endif /* JSNodeList_h */
diff --git a/Source/JavaScriptCore/API/tests/Node.c b/Source/JavaScriptCore/API/tests/Node.c
new file mode 100644
index 0000000..913da0a
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/Node.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#include "Node.h"
+#include <stddef.h>
+#include <stdlib.h>
+
+Node* Node_new(void)
+{
+ Node* node = (Node*)malloc(sizeof(Node));
+ node->refCount = 0;
+ node->nodeType = "Node";
+ node->childNodesTail = NULL;
+
+ return node;
+}
+
+void Node_appendChild(Node* node, Node* child)
+{
+ Node_ref(child);
+ NodeLink* nodeLink = (NodeLink*)malloc(sizeof(NodeLink));
+ nodeLink->node = child;
+ nodeLink->prev = node->childNodesTail;
+ node->childNodesTail = nodeLink;
+}
+
+void Node_removeChild(Node* node, Node* child)
+{
+ /* 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) {
+ if (current->node == child) {
+ Node_deref(current->node);
+ *currentHandle = current->prev;
+ free(current);
+ break;
+ }
+ }
+}
+
+void Node_replaceChild(Node* node, Node* newChild, Node* oldChild)
+{
+ /* Linear search from tail -- good enough for our purposes here */
+ NodeLink* current;
+ for (current = node->childNodesTail; current; current = current->prev) {
+ if (current->node == oldChild) {
+ Node_deref(current->node);
+ current->node = newChild;
+ }
+ }
+}
+
+void Node_ref(Node* node)
+{
+ ++node->refCount;
+}
+
+void Node_deref(Node* node)
+{
+ if (--node->refCount == 0)
+ free(node);
+}
diff --git a/Source/JavaScriptCore/API/tests/Node.h b/Source/JavaScriptCore/API/tests/Node.h
new file mode 100644
index 0000000..e9250b3
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/Node.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2006 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 Node_h
+#define Node_h
+
+typedef struct __Node Node;
+typedef struct __NodeLink NodeLink;
+
+struct __NodeLink {
+ Node* node;
+ NodeLink* prev;
+};
+
+struct __Node {
+ unsigned refCount;
+ const char* nodeType;
+ NodeLink* childNodesTail;
+};
+
+extern Node* Node_new(void);
+extern void Node_ref(Node* node);
+extern void Node_deref(Node* node);
+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 */
diff --git a/Source/JavaScriptCore/API/tests/NodeList.c b/Source/JavaScriptCore/API/tests/NodeList.c
new file mode 100644
index 0000000..ae4c170
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/NodeList.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#include "NodeList.h"
+
+#include <stdlib.h>
+
+extern NodeList* NodeList_new(Node* parentNode)
+{
+ Node_ref(parentNode);
+
+ NodeList* nodeList = (NodeList*)malloc(sizeof(NodeList));
+ nodeList->parentNode = parentNode;
+ nodeList->refCount = 0;
+ return nodeList;
+}
+
+extern unsigned NodeList_length(NodeList* nodeList)
+{
+ /* Linear count from tail -- good enough for our purposes here */
+ unsigned i = 0;
+ NodeLink* n = nodeList->parentNode->childNodesTail;
+ while (n) {
+ n = n->prev;
+ ++i;
+ }
+
+ return i;
+}
+
+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 */
+ NodeLink* n = nodeList->parentNode->childNodesTail;
+ unsigned i = 0;
+ unsigned count = length - 1 - index;
+ while (i < count) {
+ ++i;
+ n = n->prev;
+ }
+ return n->node;
+}
+
+extern void NodeList_ref(NodeList* nodeList)
+{
+ ++nodeList->refCount;
+}
+
+extern void NodeList_deref(NodeList* nodeList)
+{
+ if (--nodeList->refCount == 0) {
+ Node_deref(nodeList->parentNode);
+ free(nodeList);
+ }
+}
diff --git a/Source/JavaScriptCore/API/tests/NodeList.h b/Source/JavaScriptCore/API/tests/NodeList.h
new file mode 100644
index 0000000..25b95bf
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/NodeList.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2006 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 NodeList_h
+#define NodeList_h
+
+#include "Node.h"
+
+typedef struct {
+ unsigned refCount;
+ Node* parentNode;
+} NodeList;
+
+extern NodeList* NodeList_new(Node* parentNode);
+extern unsigned NodeList_length(NodeList*);
+extern Node* NodeList_item(NodeList*, unsigned);
+extern void NodeList_ref(NodeList*);
+extern void NodeList_deref(NodeList*);
+
+#endif /* NodeList_h */
diff --git a/Source/JavaScriptCore/API/tests/minidom.c b/Source/JavaScriptCore/API/tests/minidom.c
new file mode 100644
index 0000000..43ae2c1
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/minidom.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2007 Alp Toker <alp@atoker.com>
+ *
+ * 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 "JSContextRef.h"
+#include "JSNode.h"
+#include "JSObjectRef.h"
+#include "JSStringRef.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <wtf/Assertions.h>
+#include <wtf/UnusedParam.h>
+
+static char* createStringWithContentsOfFile(const char* fileName);
+static JSValueRef print(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+
+int main(int argc, char* argv[])
+{
+ const char *scriptPath = "minidom.js";
+ if (argc > 1) {
+ scriptPath = argv[1];
+ }
+
+ JSGlobalContextRef context = JSGlobalContextCreateInGroup(NULL, NULL);
+ JSObjectRef globalObject = JSContextGetGlobalObject(context);
+
+ JSStringRef printIString = JSStringCreateWithUTF8CString("print");
+ JSObjectSetProperty(context, globalObject, printIString, JSObjectMakeFunctionWithCallback(context, printIString, print), kJSPropertyAttributeNone, NULL);
+ JSStringRelease(printIString);
+
+ JSStringRef node = JSStringCreateWithUTF8CString("Node");
+ JSObjectSetProperty(context, globalObject, node, JSObjectMakeConstructor(context, JSNode_class(context), JSNode_construct), kJSPropertyAttributeNone, NULL);
+ JSStringRelease(node);
+
+ char* scriptUTF8 = createStringWithContentsOfFile(scriptPath);
+ JSStringRef script = JSStringCreateWithUTF8CString(scriptUTF8);
+ JSValueRef exception;
+ JSValueRef result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
+ if (result)
+ printf("PASS: Test script executed successfully.\n");
+ else {
+ printf("FAIL: Test script threw exception:\n");
+ JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL);
+ size_t exceptionUTF8Size = JSStringGetMaximumUTF8CStringSize(exceptionIString);
+ char* exceptionUTF8 = (char*)malloc(exceptionUTF8Size);
+ JSStringGetUTF8CString(exceptionIString, exceptionUTF8, exceptionUTF8Size);
+ printf("%s\n", exceptionUTF8);
+ free(exceptionUTF8);
+ JSStringRelease(exceptionIString);
+ }
+ JSStringRelease(script);
+ free(scriptUTF8);
+
+ globalObject = 0;
+ JSGlobalContextRelease(context);
+ printf("PASS: Program exited normally.\n");
+ return 0;
+}
+
+static JSValueRef print(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(thisObject);
+
+ if (argumentCount > 0) {
+ JSStringRef string = JSValueToStringCopy(context, arguments[0], exception);
+ size_t numChars = JSStringGetMaximumUTF8CStringSize(string);
+ char stringUTF8[numChars];
+ JSStringGetUTF8CString(string, stringUTF8, numChars);
+ printf("%s\n", stringUTF8);
+ }
+
+ return JSValueMakeUndefined(context);
+}
+
+static char* createStringWithContentsOfFile(const char* fileName)
+{
+ char* buffer;
+
+ size_t buffer_size = 0;
+ size_t buffer_capacity = 1024;
+ buffer = (char*)malloc(buffer_capacity);
+
+ FILE* f = fopen(fileName, "r");
+ if (!f) {
+ fprintf(stderr, "Could not open file: %s\n", fileName);
+ return 0;
+ }
+
+ 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' */
+ buffer_capacity *= 2;
+ buffer = (char*)realloc(buffer, buffer_capacity);
+ ASSERT(buffer);
+ }
+
+ ASSERT(buffer_size < buffer_capacity);
+ }
+ fclose(f);
+ buffer[buffer_size] = '\0';
+
+ return buffer;
+}
diff --git a/Source/JavaScriptCore/API/tests/minidom.html b/Source/JavaScriptCore/API/tests/minidom.html
new file mode 100644
index 0000000..7ea4747
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/minidom.html
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src="minidom.js"></script>
+</head>
+
+<body onload="test()">
+ <pre id='pre'></pre>
+</body>
+</html>
diff --git a/Source/JavaScriptCore/API/tests/minidom.js b/Source/JavaScriptCore/API/tests/minidom.js
new file mode 100644
index 0000000..4808960
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/minidom.js
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+function shouldBe(a, b)
+{
+ var evalA;
+ try {
+ evalA = eval(a);
+ } catch(e) {
+ evalA = e;
+ }
+
+ if (evalA == b || isNaN(evalA) && typeof evalA == 'number' && isNaN(b) && typeof b == 'number')
+ print("PASS: " + a + " should be " + b + " and is.", "green");
+ else
+ print("__FAIL__: " + a + " should be " + b + " but instead is " + evalA + ".", "red");
+}
+
+function test()
+{
+ print("Node is " + Node);
+ for (var p in Node)
+ print(p + ": " + Node[p]);
+
+ node = new Node();
+ print("node is " + node);
+ for (var p in node)
+ print(p + ": " + node[p]);
+
+ child1 = new Node();
+ child2 = new Node();
+ child3 = new Node();
+
+ node.appendChild(child1);
+ node.appendChild(child2);
+
+ var childNodes = node.childNodes;
+
+ for (var i = 0; i < childNodes.length + 1; i++) {
+ print("item " + i + ": " + childNodes.item(i));
+ }
+
+ for (var i = 0; i < childNodes.length + 1; i++) {
+ print(i + ": " + childNodes[i]);
+ }
+
+ node.removeChild(child1);
+ node.replaceChild(child3, child2);
+
+ for (var i = 0; i < childNodes.length + 1; i++) {
+ print("item " + i + ": " + childNodes.item(i));
+ }
+
+ for (var i = 0; i < childNodes.length + 1; i++) {
+ print(i + ": " + childNodes[i]);
+ }
+
+ try {
+ node.appendChild(null);
+ } catch(e) {
+ print("caught: " + e);
+ }
+
+ try {
+ var o = new Object();
+ o.appendChild = node.appendChild;
+ o.appendChild(node);
+ } catch(e) {
+ print("caught: " + e);
+ }
+
+ try {
+ node.appendChild();
+ } catch(e) {
+ print("caught: " + e);
+ }
+
+ oldNodeType = node.nodeType;
+ node.nodeType = 1;
+ shouldBe("node.nodeType", oldNodeType);
+
+ shouldBe("node instanceof Node", true);
+ shouldBe("new Object() instanceof Node", false);
+
+ print(Node);
+}
+
+test();
diff --git a/Source/JavaScriptCore/API/tests/testapi.c b/Source/JavaScriptCore/API/tests/testapi.c
new file mode 100644
index 0000000..1ecfc7e
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/testapi.c
@@ -0,0 +1,1458 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+#include "JavaScriptCore.h"
+#include "JSBasePrivate.h"
+#include "JSContextRefPrivate.h"
+#include "JSObjectRefPrivate.h"
+#include <math.h>
+#define ASSERT_DISABLED 0
+#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;
+static int failed;
+static void assertEqualsAsBoolean(JSValueRef value, bool expectedValue)
+{
+ if (JSValueToBoolean(context, value) != expectedValue) {
+ fprintf(stderr, "assertEqualsAsBoolean failed: %p, %d\n", value, expectedValue);
+ failed = 1;
+ }
+}
+
+static void assertEqualsAsNumber(JSValueRef value, double expectedValue)
+{
+ double number = JSValueToNumber(context, value, NULL);
+
+ // FIXME <rdar://4668451> - On i386 the isnan(double) macro tries to map to the isnan(float) function,
+ // causing a build break with -Wshorten-64-to-32 enabled. The issue is known by the appropriate team.
+ // After that's resolved, we can remove these casts
+ if (number != expectedValue && !(isnan((float)number) && isnan((float)expectedValue))) {
+ fprintf(stderr, "assertEqualsAsNumber failed: %p, %lf\n", value, expectedValue);
+ failed = 1;
+ }
+}
+
+static void assertEqualsAsUTF8String(JSValueRef value, const char* expectedValue)
+{
+ JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL);
+
+ size_t jsSize = JSStringGetMaximumUTF8CStringSize(valueAsString);
+ char* jsBuffer = (char*)malloc(jsSize);
+ JSStringGetUTF8CString(valueAsString, jsBuffer, jsSize);
+
+ unsigned i;
+ for (i = 0; jsBuffer[i]; i++) {
+ if (jsBuffer[i] != expectedValue[i]) {
+ fprintf(stderr, "assertEqualsAsUTF8String failed at character %d: %c(%d) != %c(%d)\n", i, jsBuffer[i], jsBuffer[i], expectedValue[i], expectedValue[i]);
+ failed = 1;
+ }
+ }
+
+ if (jsSize < strlen(jsBuffer) + 1) {
+ fprintf(stderr, "assertEqualsAsUTF8String failed: jsSize was too small\n");
+ failed = 1;
+ }
+
+ free(jsBuffer);
+ JSStringRelease(valueAsString);
+}
+
+static void assertEqualsAsCharactersPtr(JSValueRef value, const char* expectedValue)
+{
+ JSStringRef valueAsString = JSValueToStringCopy(context, value, NULL);
+
+ size_t jsLength = JSStringGetLength(valueAsString);
+ const JSChar* jsBuffer = JSStringGetCharactersPtr(valueAsString);
+
+ CFStringRef expectedValueAsCFString = CFStringCreateWithCString(kCFAllocatorDefault,
+ expectedValue,
+ kCFStringEncodingUTF8);
+ CFIndex cfLength = CFStringGetLength(expectedValueAsCFString);
+ UniChar* cfBuffer = (UniChar*)malloc(cfLength * sizeof(UniChar));
+ CFStringGetCharacters(expectedValueAsCFString, CFRangeMake(0, cfLength), cfBuffer);
+ CFRelease(expectedValueAsCFString);
+
+ if (memcmp(jsBuffer, cfBuffer, cfLength * sizeof(UniChar)) != 0) {
+ fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsBuffer != cfBuffer\n");
+ failed = 1;
+ }
+
+ if (jsLength != (size_t)cfLength) {
+ fprintf(stderr, "assertEqualsAsCharactersPtr failed: jsLength(%ld) != cfLength(%ld)\n", jsLength, cfLength);
+ failed = 1;
+ }
+
+ free(cfBuffer);
+ JSStringRelease(valueAsString);
+}
+
+static bool timeZoneIsPST()
+{
+ char timeZoneName[70];
+ struct tm gtm;
+ memset(&gtm, 0, sizeof(gtm));
+ strftime(timeZoneName, sizeof(timeZoneName), "%Z", &gtm);
+
+ return 0 == strcmp("PST", timeZoneName);
+}
+
+static JSValueRef jsGlobalValue; // non-stack value for testing JSValueProtect()
+
+/* MyObject pseudo-class */
+
+static bool MyObject_hasProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName)
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(object);
+
+ if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")
+ || JSStringIsEqualToUTF8CString(propertyName, "cantFind")
+ || JSStringIsEqualToUTF8CString(propertyName, "throwOnGet")
+ || JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")
+ || JSStringIsEqualToUTF8CString(propertyName, "hasPropertyLie")
+ || JSStringIsEqualToUTF8CString(propertyName, "0")) {
+ return true;
+ }
+
+ return false;
+}
+
+static JSValueRef MyObject_getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(object);
+
+ if (JSStringIsEqualToUTF8CString(propertyName, "alwaysOne")) {
+ return JSValueMakeNumber(context, 1);
+ }
+
+ if (JSStringIsEqualToUTF8CString(propertyName, "myPropertyName")) {
+ return JSValueMakeNumber(context, 1);
+ }
+
+ if (JSStringIsEqualToUTF8CString(propertyName, "cantFind")) {
+ return JSValueMakeUndefined(context);
+ }
+
+ if (JSStringIsEqualToUTF8CString(propertyName, "hasPropertyLie")) {
+ return 0;
+ }
+
+ if (JSStringIsEqualToUTF8CString(propertyName, "throwOnGet")) {
+ return JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), object, JSStringCreateWithUTF8CString("test script"), 1, exception);
+ }
+
+ if (JSStringIsEqualToUTF8CString(propertyName, "0")) {
+ *exception = JSValueMakeNumber(context, 1);
+ return JSValueMakeNumber(context, 1);
+ }
+
+ return JSValueMakeNull(context);
+}
+
+static bool MyObject_setProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(value);
+ UNUSED_PARAM(exception);
+
+ if (JSStringIsEqualToUTF8CString(propertyName, "cantSet"))
+ return true; // pretend we set the property in order to swallow it
+
+ if (JSStringIsEqualToUTF8CString(propertyName, "throwOnSet")) {
+ JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), object, JSStringCreateWithUTF8CString("test script"), 1, exception);
+ }
+
+ return false;
+}
+
+static bool MyObject_deleteProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(object);
+
+ if (JSStringIsEqualToUTF8CString(propertyName, "cantDelete"))
+ return true;
+
+ if (JSStringIsEqualToUTF8CString(propertyName, "throwOnDelete")) {
+ JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), object, JSStringCreateWithUTF8CString("test script"), 1, exception);
+ return false;
+ }
+
+ return false;
+}
+
+static void MyObject_getPropertyNames(JSContextRef context, JSObjectRef object, JSPropertyNameAccumulatorRef propertyNames)
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(object);
+
+ JSStringRef propertyName;
+
+ propertyName = JSStringCreateWithUTF8CString("alwaysOne");
+ JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+ JSStringRelease(propertyName);
+
+ propertyName = JSStringCreateWithUTF8CString("myPropertyName");
+ JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
+ JSStringRelease(propertyName);
+}
+
+static JSValueRef MyObject_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(thisObject);
+ UNUSED_PARAM(exception);
+
+ if (argumentCount > 0 && JSValueIsString(context, arguments[0]) && JSStringIsEqualToUTF8CString(JSValueToStringCopy(context, arguments[0], 0), "throwOnCall")) {
+ JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), object, JSStringCreateWithUTF8CString("test script"), 1, exception);
+ return JSValueMakeUndefined(context);
+ }
+
+ if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0)))
+ return JSValueMakeNumber(context, 1);
+
+ return JSValueMakeUndefined(context);
+}
+
+static JSObjectRef MyObject_callAsConstructor(JSContextRef context, JSObjectRef object, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(object);
+
+ if (argumentCount > 0 && JSValueIsString(context, arguments[0]) && JSStringIsEqualToUTF8CString(JSValueToStringCopy(context, arguments[0], 0), "throwOnConstruct")) {
+ JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), object, JSStringCreateWithUTF8CString("test script"), 1, exception);
+ return object;
+ }
+
+ if (argumentCount > 0 && JSValueIsStrictEqual(context, arguments[0], JSValueMakeNumber(context, 0)))
+ return JSValueToObject(context, JSValueMakeNumber(context, 1), exception);
+
+ return JSValueToObject(context, JSValueMakeNumber(context, 0), exception);
+}
+
+static bool MyObject_hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleValue, JSValueRef* exception)
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(constructor);
+
+ if (JSValueIsString(context, possibleValue) && JSStringIsEqualToUTF8CString(JSValueToStringCopy(context, possibleValue, 0), "throwOnHasInstance")) {
+ JSEvaluateScript(context, JSStringCreateWithUTF8CString("throw 'an exception'"), constructor, JSStringCreateWithUTF8CString("test script"), 1, exception);
+ return false;
+ }
+
+ JSStringRef numberString = JSStringCreateWithUTF8CString("Number");
+ JSObjectRef numberConstructor = JSValueToObject(context, JSObjectGetProperty(context, JSContextGetGlobalObject(context), numberString, exception), exception);
+ JSStringRelease(numberString);
+
+ return JSValueIsInstanceOfConstructor(context, possibleValue, numberConstructor, exception);
+}
+
+static JSValueRef MyObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception)
+{
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(exception);
+
+ 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;
+ }
+
+ // string conversion -- forward to default object class
+ return JSValueMakeNull(context);
+}
+
+static JSStaticValue evilStaticValues[] = {
+ { "nullGetSet", 0, 0, kJSPropertyAttributeNone },
+ { 0, 0, 0, 0 }
+};
+
+static JSStaticFunction evilStaticFunctions[] = {
+ { "nullCall", 0, kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+JSClassDefinition MyObject_definition = {
+ 0,
+ kJSClassAttributeNone,
+
+ "MyObject",
+ NULL,
+
+ evilStaticValues,
+ evilStaticFunctions,
+
+ NULL,
+ NULL,
+ MyObject_hasProperty,
+ MyObject_getProperty,
+ MyObject_setProperty,
+ MyObject_deleteProperty,
+ MyObject_getPropertyNames,
+ MyObject_callAsFunction,
+ MyObject_callAsConstructor,
+ MyObject_hasInstance,
+ MyObject_convertToType,
+};
+
+static JSClassRef MyObject_class(JSContextRef context)
+{
+ UNUSED_PARAM(context);
+
+ static JSClassRef jsClass;
+ if (!jsClass)
+ jsClass = JSClassCreate(&MyObject_definition);
+
+ return jsClass;
+}
+
+static bool EvilExceptionObject_hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleValue, JSValueRef* exception)
+{
+ UNUSED_PARAM(context);
+ UNUSED_PARAM(constructor);
+
+ JSStringRef hasInstanceName = JSStringCreateWithUTF8CString("hasInstance");
+ JSValueRef hasInstance = JSObjectGetProperty(context, constructor, hasInstanceName, exception);
+ JSStringRelease(hasInstanceName);
+ if (!hasInstance)
+ return false;
+ JSObjectRef function = JSValueToObject(context, hasInstance, exception);
+ JSValueRef result = JSObjectCallAsFunction(context, function, constructor, 1, &possibleValue, exception);
+ return result && JSValueToBoolean(context, result);
+}
+
+static JSValueRef EvilExceptionObject_convertToType(JSContextRef context, JSObjectRef object, JSType type, JSValueRef* exception)
+{
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(exception);
+ JSStringRef funcName;
+ switch (type) {
+ case kJSTypeNumber:
+ funcName = JSStringCreateWithUTF8CString("toNumber");
+ break;
+ case kJSTypeString:
+ funcName = JSStringCreateWithUTF8CString("toStringExplicit");
+ break;
+ default:
+ return JSValueMakeNull(context);
+ break;
+ }
+
+ JSValueRef func = JSObjectGetProperty(context, object, funcName, exception);
+ JSStringRelease(funcName);
+ JSObjectRef function = JSValueToObject(context, func, exception);
+ if (!function)
+ return JSValueMakeNull(context);
+ JSValueRef value = JSObjectCallAsFunction(context, function, object, 0, NULL, exception);
+ if (!value) {
+ JSStringRef errorString = JSStringCreateWithUTF8CString("convertToType failed");
+ JSValueRef errorStringRef = JSValueMakeString(context, errorString);
+ JSStringRelease(errorString);
+ return errorStringRef;
+ }
+ return value;
+}
+
+JSClassDefinition EvilExceptionObject_definition = {
+ 0,
+ kJSClassAttributeNone,
+
+ "EvilExceptionObject",
+ NULL,
+
+ NULL,
+ NULL,
+
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ EvilExceptionObject_hasInstance,
+ EvilExceptionObject_convertToType,
+};
+
+static JSClassRef EvilExceptionObject_class(JSContextRef context)
+{
+ UNUSED_PARAM(context);
+
+ static JSClassRef jsClass;
+ if (!jsClass)
+ jsClass = JSClassCreate(&EvilExceptionObject_definition);
+
+ return jsClass;
+}
+
+JSClassDefinition EmptyObject_definition = {
+ 0,
+ kJSClassAttributeNone,
+
+ NULL,
+ NULL,
+
+ NULL,
+ NULL,
+
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+};
+
+static JSClassRef EmptyObject_class(JSContextRef context)
+{
+ UNUSED_PARAM(context);
+
+ static JSClassRef jsClass;
+ if (!jsClass)
+ jsClass = JSClassCreate(&EmptyObject_definition);
+
+ return jsClass;
+}
+
+
+static JSValueRef Base_get(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(propertyName);
+ UNUSED_PARAM(exception);
+
+ return JSValueMakeNumber(ctx, 1); // distinguish base get form derived get
+}
+
+static bool Base_set(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+{
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(propertyName);
+ UNUSED_PARAM(value);
+
+ *exception = JSValueMakeNumber(ctx, 1); // distinguish base set from derived set
+ return true;
+}
+
+static JSValueRef Base_callAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(function);
+ UNUSED_PARAM(thisObject);
+ UNUSED_PARAM(argumentCount);
+ UNUSED_PARAM(arguments);
+ UNUSED_PARAM(exception);
+
+ return JSValueMakeNumber(ctx, 1); // distinguish base call from derived call
+}
+
+static JSStaticFunction Base_staticFunctions[] = {
+ { "baseProtoDup", NULL, kJSPropertyAttributeNone },
+ { "baseProto", Base_callAsFunction, kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+static JSStaticValue Base_staticValues[] = {
+ { "baseDup", Base_get, Base_set, kJSPropertyAttributeNone },
+ { "baseOnly", Base_get, Base_set, kJSPropertyAttributeNone },
+ { 0, 0, 0, 0 }
+};
+
+static bool TestInitializeFinalize;
+static void Base_initialize(JSContextRef context, JSObjectRef object)
+{
+ UNUSED_PARAM(context);
+
+ if (TestInitializeFinalize) {
+ ASSERT((void*)1 == JSObjectGetPrivate(object));
+ JSObjectSetPrivate(object, (void*)2);
+ }
+}
+
+static unsigned Base_didFinalize;
+static void Base_finalize(JSObjectRef object)
+{
+ UNUSED_PARAM(object);
+ if (TestInitializeFinalize) {
+ ASSERT((void*)4 == JSObjectGetPrivate(object));
+ Base_didFinalize = true;
+ }
+}
+
+static JSClassRef Base_class(JSContextRef context)
+{
+ UNUSED_PARAM(context);
+
+ static JSClassRef jsClass;
+ if (!jsClass) {
+ JSClassDefinition definition = kJSClassDefinitionEmpty;
+ definition.staticValues = Base_staticValues;
+ definition.staticFunctions = Base_staticFunctions;
+ definition.initialize = Base_initialize;
+ definition.finalize = Base_finalize;
+ jsClass = JSClassCreate(&definition);
+ }
+ return jsClass;
+}
+
+static JSValueRef Derived_get(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(propertyName);
+ UNUSED_PARAM(exception);
+
+ return JSValueMakeNumber(ctx, 2); // distinguish base get form derived get
+}
+
+static bool Derived_set(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+{
+ UNUSED_PARAM(ctx);
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(propertyName);
+ UNUSED_PARAM(value);
+
+ *exception = JSValueMakeNumber(ctx, 2); // distinguish base set from derived set
+ return true;
+}
+
+static JSValueRef Derived_callAsFunction(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(function);
+ UNUSED_PARAM(thisObject);
+ UNUSED_PARAM(argumentCount);
+ UNUSED_PARAM(arguments);
+ UNUSED_PARAM(exception);
+
+ return JSValueMakeNumber(ctx, 2); // distinguish base call from derived call
+}
+
+static JSStaticFunction Derived_staticFunctions[] = {
+ { "protoOnly", Derived_callAsFunction, kJSPropertyAttributeNone },
+ { "protoDup", NULL, kJSPropertyAttributeNone },
+ { "baseProtoDup", Derived_callAsFunction, kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+static JSStaticValue Derived_staticValues[] = {
+ { "derivedOnly", Derived_get, Derived_set, kJSPropertyAttributeNone },
+ { "protoDup", Derived_get, Derived_set, kJSPropertyAttributeNone },
+ { "baseDup", Derived_get, Derived_set, kJSPropertyAttributeNone },
+ { 0, 0, 0, 0 }
+};
+
+static void Derived_initialize(JSContextRef context, JSObjectRef object)
+{
+ UNUSED_PARAM(context);
+
+ if (TestInitializeFinalize) {
+ ASSERT((void*)2 == JSObjectGetPrivate(object));
+ JSObjectSetPrivate(object, (void*)3);
+ }
+}
+
+static void Derived_finalize(JSObjectRef object)
+{
+ if (TestInitializeFinalize) {
+ ASSERT((void*)3 == JSObjectGetPrivate(object));
+ JSObjectSetPrivate(object, (void*)4);
+ }
+}
+
+static JSClassRef Derived_class(JSContextRef context)
+{
+ static JSClassRef jsClass;
+ if (!jsClass) {
+ JSClassDefinition definition = kJSClassDefinitionEmpty;
+ definition.parentClass = Base_class(context);
+ definition.staticValues = Derived_staticValues;
+ definition.staticFunctions = Derived_staticFunctions;
+ definition.initialize = Derived_initialize;
+ definition.finalize = Derived_finalize;
+ jsClass = JSClassCreate(&definition);
+ }
+ return jsClass;
+}
+
+static JSClassRef Derived2_class(JSContextRef context)
+{
+ static JSClassRef jsClass;
+ if (!jsClass) {
+ JSClassDefinition definition = kJSClassDefinitionEmpty;
+ definition.parentClass = Derived_class(context);
+ jsClass = JSClassCreate(&definition);
+ }
+ return jsClass;
+}
+
+static JSValueRef print_callAsFunction(JSContextRef ctx, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(functionObject);
+ UNUSED_PARAM(thisObject);
+ UNUSED_PARAM(exception);
+
+ ASSERT(JSContextGetGlobalContext(ctx) == context);
+
+ if (argumentCount > 0) {
+ JSStringRef string = JSValueToStringCopy(ctx, arguments[0], NULL);
+ size_t sizeUTF8 = JSStringGetMaximumUTF8CStringSize(string);
+ char* stringUTF8 = (char*)malloc(sizeUTF8);
+ JSStringGetUTF8CString(string, stringUTF8, sizeUTF8);
+ printf("%s\n", stringUTF8);
+ free(stringUTF8);
+ JSStringRelease(string);
+ }
+
+ return JSValueMakeUndefined(ctx);
+}
+
+static JSObjectRef myConstructor_callAsConstructor(JSContextRef context, JSObjectRef constructorObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(constructorObject);
+ UNUSED_PARAM(exception);
+
+ JSObjectRef result = JSObjectMake(context, NULL, NULL);
+ if (argumentCount > 0) {
+ JSStringRef value = JSStringCreateWithUTF8CString("value");
+ JSObjectSetProperty(context, result, value, arguments[0], kJSPropertyAttributeNone, NULL);
+ JSStringRelease(value);
+ }
+
+ return result;
+}
+
+
+static void globalObject_initialize(JSContextRef context, JSObjectRef object)
+{
+ UNUSED_PARAM(object);
+ // Ensure that an execution context is passed in
+ ASSERT(context);
+
+ // Ensure that the global object is set to the object that we were passed
+ JSObjectRef globalObject = JSContextGetGlobalObject(context);
+ ASSERT(globalObject);
+ ASSERT(object == globalObject);
+
+ // Ensure that the standard global properties have been set on the global object
+ JSStringRef array = JSStringCreateWithUTF8CString("Array");
+ JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL);
+ JSStringRelease(array);
+
+ UNUSED_PARAM(arrayConstructor);
+ ASSERT(arrayConstructor);
+}
+
+static JSValueRef globalObject_get(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
+{
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(propertyName);
+ UNUSED_PARAM(exception);
+
+ return JSValueMakeNumber(ctx, 3);
+}
+
+static bool globalObject_set(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
+{
+ UNUSED_PARAM(object);
+ UNUSED_PARAM(propertyName);
+ UNUSED_PARAM(value);
+
+ *exception = JSValueMakeNumber(ctx, 3);
+ return true;
+}
+
+static JSValueRef globalObject_call(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(function);
+ UNUSED_PARAM(thisObject);
+ UNUSED_PARAM(argumentCount);
+ UNUSED_PARAM(arguments);
+ UNUSED_PARAM(exception);
+
+ return JSValueMakeNumber(ctx, 3);
+}
+
+static JSValueRef functionGC(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+ UNUSED_PARAM(function);
+ UNUSED_PARAM(thisObject);
+ UNUSED_PARAM(argumentCount);
+ UNUSED_PARAM(arguments);
+ UNUSED_PARAM(exception);
+ JSGarbageCollect(context);
+ return JSValueMakeUndefined(context);
+}
+
+static JSStaticValue globalObject_staticValues[] = {
+ { "globalStaticValue", globalObject_get, globalObject_set, kJSPropertyAttributeNone },
+ { 0, 0, 0, 0 }
+};
+
+static JSStaticFunction globalObject_staticFunctions[] = {
+ { "globalStaticFunction", globalObject_call, kJSPropertyAttributeNone },
+ { "gc", functionGC, kJSPropertyAttributeNone },
+ { 0, 0, 0 }
+};
+
+static char* createStringWithContentsOfFile(const char* fileName);
+
+static void testInitializeFinalize()
+{
+ JSObjectRef o = JSObjectMake(context, Derived_class(context), (void*)1);
+ UNUSED_PARAM(o);
+ ASSERT(JSObjectGetPrivate(o) == (void*)3);
+}
+
+static JSValueRef jsNumberValue = NULL;
+
+static JSObjectRef aHeapRef = NULL;
+
+static void makeGlobalNumberValue(JSContextRef context) {
+ JSValueRef v = JSValueMakeNumber(context, 420);
+ JSValueProtect(context, v);
+ jsNumberValue = v;
+ v = NULL;
+}
+
+static bool assertTrue(bool value, const char* message)
+{
+ if (!value) {
+ if (message)
+ fprintf(stderr, "assertTrue failed: '%s'\n", message);
+ else
+ fprintf(stderr, "assertTrue failed.\n");
+ failed = 1;
+ }
+ return value;
+}
+
+static bool checkForCycleInPrototypeChain()
+{
+ bool result = true;
+ JSGlobalContextRef context = JSGlobalContextCreate(0);
+ JSObjectRef object1 = JSObjectMake(context, /* jsClass */ 0, /* data */ 0);
+ JSObjectRef object2 = JSObjectMake(context, /* jsClass */ 0, /* data */ 0);
+ JSObjectRef object3 = JSObjectMake(context, /* jsClass */ 0, /* data */ 0);
+
+ JSObjectSetPrototype(context, object1, JSValueMakeNull(context));
+ ASSERT(JSValueIsNull(context, JSObjectGetPrototype(context, object1)));
+
+ // object1 -> object1
+ JSObjectSetPrototype(context, object1, object1);
+ result &= assertTrue(JSValueIsNull(context, JSObjectGetPrototype(context, object1)), "It is possible to assign self as a prototype");
+
+ // object1 -> object2 -> object1
+ JSObjectSetPrototype(context, object2, object1);
+ ASSERT(JSValueIsStrictEqual(context, JSObjectGetPrototype(context, object2), object1));
+ JSObjectSetPrototype(context, object1, object2);
+ result &= assertTrue(JSValueIsNull(context, JSObjectGetPrototype(context, object1)), "It is possible to close a prototype chain cycle");
+
+ // object1 -> object2 -> object3 -> object1
+ JSObjectSetPrototype(context, object2, object3);
+ ASSERT(JSValueIsStrictEqual(context, JSObjectGetPrototype(context, object2), object3));
+ JSObjectSetPrototype(context, object1, object2);
+ ASSERT(JSValueIsStrictEqual(context, JSObjectGetPrototype(context, object1), object2));
+ JSObjectSetPrototype(context, object3, object1);
+ result &= assertTrue(!JSValueIsStrictEqual(context, JSObjectGetPrototype(context, object3), object1), "It is possible to close a prototype chain cycle");
+
+ JSValueRef exception;
+ JSStringRef code = JSStringCreateWithUTF8CString("o = { }; p = { }; o.__proto__ = p; p.__proto__ = o");
+ JSStringRef file = JSStringCreateWithUTF8CString("");
+ result &= assertTrue(!JSEvaluateScript(context, code, /* thisObject*/ 0, file, 1, &exception)
+ , "An exception should be thrown");
+
+ JSStringRelease(code);
+ JSStringRelease(file);
+ JSGlobalContextRelease(context);
+ return result;
+}
+
+int main(int argc, char* argv[])
+{
+ const char *scriptPath = "testapi.js";
+ if (argc > 1) {
+ scriptPath = argv[1];
+ }
+
+ // Test garbage collection with a fresh context
+ context = JSGlobalContextCreateInGroup(NULL, NULL);
+ TestInitializeFinalize = true;
+ testInitializeFinalize();
+ JSGlobalContextRelease(context);
+ TestInitializeFinalize = false;
+
+ ASSERT(Base_didFinalize);
+
+ JSClassDefinition globalObjectClassDefinition = kJSClassDefinitionEmpty;
+ globalObjectClassDefinition.initialize = globalObject_initialize;
+ globalObjectClassDefinition.staticValues = globalObject_staticValues;
+ globalObjectClassDefinition.staticFunctions = globalObject_staticFunctions;
+ globalObjectClassDefinition.attributes = kJSClassAttributeNoAutomaticPrototype;
+ JSClassRef globalObjectClass = JSClassCreate(&globalObjectClassDefinition);
+ context = JSGlobalContextCreateInGroup(NULL, globalObjectClass);
+
+ JSGlobalContextRetain(context);
+ JSGlobalContextRelease(context);
+ ASSERT(JSContextGetGlobalContext(context) == context);
+
+ JSReportExtraMemoryCost(context, 0);
+ JSReportExtraMemoryCost(context, 1);
+ JSReportExtraMemoryCost(context, 1024);
+
+ JSObjectRef globalObject = JSContextGetGlobalObject(context);
+ ASSERT(JSValueIsObject(context, globalObject));
+
+ JSValueRef jsUndefined = JSValueMakeUndefined(context);
+ JSValueRef jsNull = JSValueMakeNull(context);
+ JSValueRef jsTrue = JSValueMakeBoolean(context, true);
+ JSValueRef jsFalse = JSValueMakeBoolean(context, false);
+ JSValueRef jsZero = JSValueMakeNumber(context, 0);
+ JSValueRef jsOne = JSValueMakeNumber(context, 1);
+ JSValueRef jsOneThird = JSValueMakeNumber(context, 1.0 / 3.0);
+ JSObjectRef jsObjectNoProto = JSObjectMake(context, NULL, NULL);
+ JSObjectSetPrototype(context, jsObjectNoProto, JSValueMakeNull(context));
+
+ // FIXME: test funny utf8 characters
+ JSStringRef jsEmptyIString = JSStringCreateWithUTF8CString("");
+ JSValueRef jsEmptyString = JSValueMakeString(context, jsEmptyIString);
+
+ JSStringRef jsOneIString = JSStringCreateWithUTF8CString("1");
+ JSValueRef jsOneString = JSValueMakeString(context, jsOneIString);
+
+ UniChar singleUniChar = 65; // Capital A
+ CFMutableStringRef cfString =
+ CFStringCreateMutableWithExternalCharactersNoCopy(kCFAllocatorDefault,
+ &singleUniChar,
+ 1,
+ 1,
+ kCFAllocatorNull);
+
+ JSStringRef jsCFIString = JSStringCreateWithCFString(cfString);
+ JSValueRef jsCFString = JSValueMakeString(context, jsCFIString);
+
+ CFStringRef cfEmptyString = CFStringCreateWithCString(kCFAllocatorDefault, "", kCFStringEncodingUTF8);
+
+ JSStringRef jsCFEmptyIString = JSStringCreateWithCFString(cfEmptyString);
+ JSValueRef jsCFEmptyString = JSValueMakeString(context, jsCFEmptyIString);
+
+ CFIndex cfStringLength = CFStringGetLength(cfString);
+ UniChar* buffer = (UniChar*)malloc(cfStringLength * sizeof(UniChar));
+ CFStringGetCharacters(cfString,
+ CFRangeMake(0, cfStringLength),
+ buffer);
+ JSStringRef jsCFIStringWithCharacters = JSStringCreateWithCharacters((JSChar*)buffer, cfStringLength);
+ JSValueRef jsCFStringWithCharacters = JSValueMakeString(context, jsCFIStringWithCharacters);
+
+ JSStringRef jsCFEmptyIStringWithCharacters = JSStringCreateWithCharacters((JSChar*)buffer, CFStringGetLength(cfEmptyString));
+ free(buffer);
+ JSValueRef jsCFEmptyStringWithCharacters = JSValueMakeString(context, jsCFEmptyIStringWithCharacters);
+
+ ASSERT(JSValueGetType(context, jsUndefined) == kJSTypeUndefined);
+ ASSERT(JSValueGetType(context, jsNull) == kJSTypeNull);
+ ASSERT(JSValueGetType(context, jsTrue) == kJSTypeBoolean);
+ ASSERT(JSValueGetType(context, jsFalse) == kJSTypeBoolean);
+ ASSERT(JSValueGetType(context, jsZero) == kJSTypeNumber);
+ ASSERT(JSValueGetType(context, jsOne) == kJSTypeNumber);
+ ASSERT(JSValueGetType(context, jsOneThird) == kJSTypeNumber);
+ ASSERT(JSValueGetType(context, jsEmptyString) == kJSTypeString);
+ ASSERT(JSValueGetType(context, jsOneString) == kJSTypeString);
+ ASSERT(JSValueGetType(context, jsCFString) == kJSTypeString);
+ ASSERT(JSValueGetType(context, jsCFStringWithCharacters) == kJSTypeString);
+ ASSERT(JSValueGetType(context, jsCFEmptyString) == kJSTypeString);
+ ASSERT(JSValueGetType(context, jsCFEmptyStringWithCharacters) == kJSTypeString);
+
+ JSObjectRef myObject = JSObjectMake(context, MyObject_class(context), NULL);
+ JSStringRef myObjectIString = JSStringCreateWithUTF8CString("MyObject");
+ JSObjectSetProperty(context, globalObject, myObjectIString, myObject, kJSPropertyAttributeNone, NULL);
+ JSStringRelease(myObjectIString);
+
+ JSObjectRef EvilExceptionObject = JSObjectMake(context, EvilExceptionObject_class(context), NULL);
+ JSStringRef EvilExceptionObjectIString = JSStringCreateWithUTF8CString("EvilExceptionObject");
+ JSObjectSetProperty(context, globalObject, EvilExceptionObjectIString, EvilExceptionObject, kJSPropertyAttributeNone, NULL);
+ JSStringRelease(EvilExceptionObjectIString);
+
+ JSObjectRef EmptyObject = JSObjectMake(context, EmptyObject_class(context), NULL);
+ JSStringRef EmptyObjectIString = JSStringCreateWithUTF8CString("EmptyObject");
+ JSObjectSetProperty(context, globalObject, EmptyObjectIString, EmptyObject, kJSPropertyAttributeNone, NULL);
+ JSStringRelease(EmptyObjectIString);
+
+ JSStringRef lengthStr = JSStringCreateWithUTF8CString("length");
+ JSObjectRef aStackRef = JSObjectMakeArray(context, 0, 0, 0);
+ aHeapRef = aStackRef;
+ JSObjectSetProperty(context, aHeapRef, lengthStr, JSValueMakeNumber(context, 10), 0, 0);
+ JSStringRef privatePropertyName = JSStringCreateWithUTF8CString("privateProperty");
+ if (!JSObjectSetPrivateProperty(context, myObject, privatePropertyName, aHeapRef)) {
+ printf("FAIL: Could not set private property.\n");
+ failed = 1;
+ } else
+ printf("PASS: Set private property.\n");
+ aStackRef = 0;
+ if (JSObjectSetPrivateProperty(context, aHeapRef, privatePropertyName, aHeapRef)) {
+ printf("FAIL: JSObjectSetPrivateProperty should fail on non-API objects.\n");
+ failed = 1;
+ } else
+ printf("PASS: Did not allow JSObjectSetPrivateProperty on a non-API object.\n");
+ if (JSObjectGetPrivateProperty(context, myObject, privatePropertyName) != aHeapRef) {
+ printf("FAIL: Could not retrieve private property.\n");
+ failed = 1;
+ } else
+ printf("PASS: Retrieved private property.\n");
+ if (JSObjectGetPrivateProperty(context, aHeapRef, privatePropertyName)) {
+ printf("FAIL: JSObjectGetPrivateProperty should return NULL when called on a non-API object.\n");
+ failed = 1;
+ } else
+ printf("PASS: JSObjectGetPrivateProperty return NULL.\n");
+
+ if (JSObjectGetProperty(context, myObject, privatePropertyName, 0) == aHeapRef) {
+ printf("FAIL: Accessed private property through ordinary property lookup.\n");
+ failed = 1;
+ } else
+ printf("PASS: Cannot access private property through ordinary property lookup.\n");
+
+ JSGarbageCollect(context);
+
+ for (int i = 0; i < 10000; i++)
+ JSObjectMake(context, 0, 0);
+
+ aHeapRef = JSValueToObject(context, JSObjectGetPrivateProperty(context, myObject, privatePropertyName), 0);
+ if (JSValueToNumber(context, JSObjectGetProperty(context, aHeapRef, lengthStr, 0), 0) != 10) {
+ printf("FAIL: Private property has been collected.\n");
+ failed = 1;
+ } else
+ printf("PASS: Private property does not appear to have been collected.\n");
+ JSStringRelease(lengthStr);
+
+ if (!JSObjectSetPrivateProperty(context, myObject, privatePropertyName, 0)) {
+ printf("FAIL: Could not set private property to NULL.\n");
+ failed = 1;
+ } else
+ printf("PASS: Set private property to NULL.\n");
+ if (JSObjectGetPrivateProperty(context, myObject, privatePropertyName)) {
+ printf("FAIL: Could not retrieve private property.\n");
+ failed = 1;
+ } else
+ printf("PASS: Retrieved private property.\n");
+
+ JSStringRef validJSON = JSStringCreateWithUTF8CString("{\"aProperty\":true}");
+ JSValueRef jsonObject = JSValueMakeFromJSONString(context, validJSON);
+ JSStringRelease(validJSON);
+ if (!JSValueIsObject(context, jsonObject)) {
+ printf("FAIL: Did not parse valid JSON correctly\n");
+ failed = 1;
+ } else
+ printf("PASS: Parsed valid JSON string.\n");
+ JSStringRef propertyName = JSStringCreateWithUTF8CString("aProperty");
+ assertEqualsAsBoolean(JSObjectGetProperty(context, JSValueToObject(context, jsonObject, 0), propertyName, 0), true);
+ JSStringRelease(propertyName);
+ JSStringRef invalidJSON = JSStringCreateWithUTF8CString("fail!");
+ if (JSValueMakeFromJSONString(context, invalidJSON)) {
+ printf("FAIL: Should return null for invalid JSON data\n");
+ failed = 1;
+ } else
+ printf("PASS: Correctly returned null for invalid JSON data.\n");
+ JSValueRef exception;
+ JSStringRef str = JSValueCreateJSONString(context, jsonObject, 0, 0);
+ if (!JSStringIsEqualToUTF8CString(str, "{\"aProperty\":true}")) {
+ printf("FAIL: Did not correctly serialise with indent of 0.\n");
+ failed = 1;
+ } else
+ printf("PASS: Correctly serialised with indent of 0.\n");
+ JSStringRelease(str);
+
+ str = JSValueCreateJSONString(context, jsonObject, 4, 0);
+ if (!JSStringIsEqualToUTF8CString(str, "{\n \"aProperty\": true\n}")) {
+ printf("FAIL: Did not correctly serialise with indent of 4.\n");
+ failed = 1;
+ } else
+ printf("PASS: Correctly serialised with indent of 4.\n");
+ JSStringRelease(str);
+ JSStringRef src = JSStringCreateWithUTF8CString("({get a(){ throw '';}})");
+ JSValueRef unstringifiableObj = JSEvaluateScript(context, src, NULL, NULL, 1, NULL);
+
+ str = JSValueCreateJSONString(context, unstringifiableObj, 4, 0);
+ if (str) {
+ printf("FAIL: Didn't return null when attempting to serialize unserializable value.\n");
+ JSStringRelease(str);
+ failed = 1;
+ } else
+ printf("PASS: returned null when attempting to serialize unserializable value.\n");
+
+ str = JSValueCreateJSONString(context, unstringifiableObj, 4, &exception);
+ if (str) {
+ printf("FAIL: Didn't return null when attempting to serialize unserializable value.\n");
+ JSStringRelease(str);
+ failed = 1;
+ } else
+ printf("PASS: returned null when attempting to serialize unserializable value.\n");
+ if (!exception) {
+ printf("FAIL: Did not set exception on serialisation error\n");
+ failed = 1;
+ } else
+ printf("PASS: set exception on serialisation error\n");
+ // Conversions that throw exceptions
+ exception = NULL;
+ ASSERT(NULL == JSValueToObject(context, jsNull, &exception));
+ ASSERT(exception);
+
+ exception = NULL;
+ // FIXME <rdar://4668451> - On i386 the isnan(double) macro tries to map to the isnan(float) function,
+ // causing a build break with -Wshorten-64-to-32 enabled. The issue is known by the appropriate team.
+ // After that's resolved, we can remove these casts
+ ASSERT(isnan((float)JSValueToNumber(context, jsObjectNoProto, &exception)));
+ ASSERT(exception);
+
+ exception = NULL;
+ ASSERT(!JSValueToStringCopy(context, jsObjectNoProto, &exception));
+ ASSERT(exception);
+
+ ASSERT(JSValueToBoolean(context, myObject));
+
+ exception = NULL;
+ ASSERT(!JSValueIsEqual(context, jsObjectNoProto, JSValueMakeNumber(context, 1), &exception));
+ ASSERT(exception);
+
+ exception = NULL;
+ JSObjectGetPropertyAtIndex(context, myObject, 0, &exception);
+ ASSERT(1 == JSValueToNumber(context, exception, NULL));
+
+ assertEqualsAsBoolean(jsUndefined, false);
+ assertEqualsAsBoolean(jsNull, false);
+ assertEqualsAsBoolean(jsTrue, true);
+ assertEqualsAsBoolean(jsFalse, false);
+ assertEqualsAsBoolean(jsZero, false);
+ assertEqualsAsBoolean(jsOne, true);
+ assertEqualsAsBoolean(jsOneThird, true);
+ assertEqualsAsBoolean(jsEmptyString, false);
+ assertEqualsAsBoolean(jsOneString, true);
+ assertEqualsAsBoolean(jsCFString, true);
+ assertEqualsAsBoolean(jsCFStringWithCharacters, true);
+ assertEqualsAsBoolean(jsCFEmptyString, false);
+ assertEqualsAsBoolean(jsCFEmptyStringWithCharacters, false);
+
+ assertEqualsAsNumber(jsUndefined, nan(""));
+ assertEqualsAsNumber(jsNull, 0);
+ assertEqualsAsNumber(jsTrue, 1);
+ assertEqualsAsNumber(jsFalse, 0);
+ assertEqualsAsNumber(jsZero, 0);
+ assertEqualsAsNumber(jsOne, 1);
+ assertEqualsAsNumber(jsOneThird, 1.0 / 3.0);
+ assertEqualsAsNumber(jsEmptyString, 0);
+ assertEqualsAsNumber(jsOneString, 1);
+ assertEqualsAsNumber(jsCFString, nan(""));
+ assertEqualsAsNumber(jsCFStringWithCharacters, nan(""));
+ assertEqualsAsNumber(jsCFEmptyString, 0);
+ assertEqualsAsNumber(jsCFEmptyStringWithCharacters, 0);
+ ASSERT(sizeof(JSChar) == sizeof(UniChar));
+
+ assertEqualsAsCharactersPtr(jsUndefined, "undefined");
+ assertEqualsAsCharactersPtr(jsNull, "null");
+ assertEqualsAsCharactersPtr(jsTrue, "true");
+ assertEqualsAsCharactersPtr(jsFalse, "false");
+ assertEqualsAsCharactersPtr(jsZero, "0");
+ assertEqualsAsCharactersPtr(jsOne, "1");
+ assertEqualsAsCharactersPtr(jsOneThird, "0.3333333333333333");
+ assertEqualsAsCharactersPtr(jsEmptyString, "");
+ assertEqualsAsCharactersPtr(jsOneString, "1");
+ assertEqualsAsCharactersPtr(jsCFString, "A");
+ assertEqualsAsCharactersPtr(jsCFStringWithCharacters, "A");
+ assertEqualsAsCharactersPtr(jsCFEmptyString, "");
+ assertEqualsAsCharactersPtr(jsCFEmptyStringWithCharacters, "");
+
+ assertEqualsAsUTF8String(jsUndefined, "undefined");
+ assertEqualsAsUTF8String(jsNull, "null");
+ assertEqualsAsUTF8String(jsTrue, "true");
+ assertEqualsAsUTF8String(jsFalse, "false");
+ assertEqualsAsUTF8String(jsZero, "0");
+ assertEqualsAsUTF8String(jsOne, "1");
+ assertEqualsAsUTF8String(jsOneThird, "0.3333333333333333");
+ assertEqualsAsUTF8String(jsEmptyString, "");
+ assertEqualsAsUTF8String(jsOneString, "1");
+ assertEqualsAsUTF8String(jsCFString, "A");
+ assertEqualsAsUTF8String(jsCFStringWithCharacters, "A");
+ assertEqualsAsUTF8String(jsCFEmptyString, "");
+ assertEqualsAsUTF8String(jsCFEmptyStringWithCharacters, "");
+
+ ASSERT(JSValueIsStrictEqual(context, jsTrue, jsTrue));
+ ASSERT(!JSValueIsStrictEqual(context, jsOne, jsOneString));
+
+ ASSERT(JSValueIsEqual(context, jsOne, jsOneString, NULL));
+ ASSERT(!JSValueIsEqual(context, jsTrue, jsFalse, NULL));
+
+ CFStringRef cfJSString = JSStringCopyCFString(kCFAllocatorDefault, jsCFIString);
+ CFStringRef cfJSEmptyString = JSStringCopyCFString(kCFAllocatorDefault, jsCFEmptyIString);
+ ASSERT(CFEqual(cfJSString, cfString));
+ ASSERT(CFEqual(cfJSEmptyString, cfEmptyString));
+ CFRelease(cfJSString);
+ CFRelease(cfJSEmptyString);
+
+ CFRelease(cfString);
+ CFRelease(cfEmptyString);
+
+ jsGlobalValue = JSObjectMake(context, NULL, NULL);
+ makeGlobalNumberValue(context);
+ JSValueProtect(context, jsGlobalValue);
+ JSGarbageCollect(context);
+ ASSERT(JSValueIsObject(context, jsGlobalValue));
+ JSValueUnprotect(context, jsGlobalValue);
+ JSValueUnprotect(context, jsNumberValue);
+
+ JSStringRef goodSyntax = JSStringCreateWithUTF8CString("x = 1;");
+ JSStringRef badSyntax = JSStringCreateWithUTF8CString("x := 1;");
+ ASSERT(JSCheckScriptSyntax(context, goodSyntax, NULL, 0, NULL));
+ ASSERT(!JSCheckScriptSyntax(context, badSyntax, NULL, 0, NULL));
+
+ JSValueRef result;
+ JSValueRef v;
+ JSObjectRef o;
+ JSStringRef string;
+
+ result = JSEvaluateScript(context, goodSyntax, NULL, NULL, 1, NULL);
+ ASSERT(result);
+ ASSERT(JSValueIsEqual(context, result, jsOne, NULL));
+
+ exception = NULL;
+ result = JSEvaluateScript(context, badSyntax, NULL, NULL, 1, &exception);
+ ASSERT(!result);
+ ASSERT(JSValueIsObject(context, exception));
+
+ JSStringRef array = JSStringCreateWithUTF8CString("Array");
+ JSObjectRef arrayConstructor = JSValueToObject(context, JSObjectGetProperty(context, globalObject, array, NULL), NULL);
+ JSStringRelease(array);
+ result = JSObjectCallAsConstructor(context, arrayConstructor, 0, NULL, NULL);
+ ASSERT(result);
+ ASSERT(JSValueIsObject(context, result));
+ ASSERT(JSValueIsInstanceOfConstructor(context, result, arrayConstructor, NULL));
+ ASSERT(!JSValueIsInstanceOfConstructor(context, JSValueMakeNull(context), arrayConstructor, NULL));
+
+ o = JSValueToObject(context, result, NULL);
+ exception = NULL;
+ ASSERT(JSValueIsUndefined(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception)));
+ ASSERT(!exception);
+
+ JSObjectSetPropertyAtIndex(context, o, 0, JSValueMakeNumber(context, 1), &exception);
+ ASSERT(!exception);
+
+ exception = NULL;
+ ASSERT(1 == JSValueToNumber(context, JSObjectGetPropertyAtIndex(context, o, 0, &exception), &exception));
+ ASSERT(!exception);
+
+ JSStringRef functionBody;
+ JSObjectRef function;
+
+ exception = NULL;
+ functionBody = JSStringCreateWithUTF8CString("rreturn Array;");
+ JSStringRef line = JSStringCreateWithUTF8CString("line");
+ 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, 1);
+ JSStringRelease(functionBody);
+ JSStringRelease(line);
+
+ exception = NULL;
+ functionBody = JSStringCreateWithUTF8CString("return Array;");
+ function = JSObjectMakeFunction(context, NULL, 0, NULL, functionBody, NULL, 1, &exception);
+ JSStringRelease(functionBody);
+ ASSERT(!exception);
+ ASSERT(JSObjectIsFunction(context, function));
+ v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, NULL);
+ ASSERT(v);
+ ASSERT(JSValueIsEqual(context, v, arrayConstructor, NULL));
+
+ exception = NULL;
+ function = JSObjectMakeFunction(context, NULL, 0, NULL, jsEmptyIString, NULL, 0, &exception);
+ ASSERT(!exception);
+ v = JSObjectCallAsFunction(context, function, NULL, 0, NULL, &exception);
+ ASSERT(v && !exception);
+ ASSERT(JSValueIsUndefined(context, v));
+
+ exception = NULL;
+ v = NULL;
+ JSStringRef foo = JSStringCreateWithUTF8CString("foo");
+ JSStringRef argumentNames[] = { foo };
+ functionBody = JSStringCreateWithUTF8CString("return foo;");
+ function = JSObjectMakeFunction(context, foo, 1, argumentNames, functionBody, NULL, 1, &exception);
+ ASSERT(function && !exception);
+ JSValueRef arguments[] = { JSValueMakeNumber(context, 2) };
+ v = JSObjectCallAsFunction(context, function, NULL, 1, arguments, &exception);
+ JSStringRelease(foo);
+ JSStringRelease(functionBody);
+
+ string = JSValueToStringCopy(context, function, NULL);
+ assertEqualsAsUTF8String(JSValueMakeString(context, string), "function foo(foo) { return foo;\n}");
+ JSStringRelease(string);
+
+ JSStringRef print = JSStringCreateWithUTF8CString("print");
+ JSObjectRef printFunction = JSObjectMakeFunctionWithCallback(context, print, print_callAsFunction);
+ JSObjectSetProperty(context, globalObject, print, printFunction, kJSPropertyAttributeNone, NULL);
+ JSStringRelease(print);
+
+ ASSERT(!JSObjectSetPrivate(printFunction, (void*)1));
+ ASSERT(!JSObjectGetPrivate(printFunction));
+
+ JSStringRef myConstructorIString = JSStringCreateWithUTF8CString("MyConstructor");
+ JSObjectRef myConstructor = JSObjectMakeConstructor(context, NULL, myConstructor_callAsConstructor);
+ JSObjectSetProperty(context, globalObject, myConstructorIString, myConstructor, kJSPropertyAttributeNone, NULL);
+ JSStringRelease(myConstructorIString);
+
+ ASSERT(!JSObjectSetPrivate(myConstructor, (void*)1));
+ ASSERT(!JSObjectGetPrivate(myConstructor));
+
+ string = JSStringCreateWithUTF8CString("Base");
+ JSObjectRef baseConstructor = JSObjectMakeConstructor(context, Base_class(context), NULL);
+ JSObjectSetProperty(context, globalObject, string, baseConstructor, kJSPropertyAttributeNone, NULL);
+ JSStringRelease(string);
+
+ string = JSStringCreateWithUTF8CString("Derived");
+ JSObjectRef derivedConstructor = JSObjectMakeConstructor(context, Derived_class(context), NULL);
+ JSObjectSetProperty(context, globalObject, string, derivedConstructor, kJSPropertyAttributeNone, NULL);
+ JSStringRelease(string);
+
+ string = JSStringCreateWithUTF8CString("Derived2");
+ JSObjectRef derived2Constructor = JSObjectMakeConstructor(context, Derived2_class(context), NULL);
+ JSObjectSetProperty(context, globalObject, string, derived2Constructor, kJSPropertyAttributeNone, NULL);
+ JSStringRelease(string);
+
+ o = JSObjectMake(context, NULL, NULL);
+ JSObjectSetProperty(context, o, jsOneIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeNone, NULL);
+ JSObjectSetProperty(context, o, jsCFIString, JSValueMakeNumber(context, 1), kJSPropertyAttributeDontEnum, NULL);
+ JSPropertyNameArrayRef nameArray = JSObjectCopyPropertyNames(context, o);
+ size_t expectedCount = JSPropertyNameArrayGetCount(nameArray);
+ size_t count;
+ for (count = 0; count < expectedCount; ++count)
+ JSPropertyNameArrayGetNameAtIndex(nameArray, count);
+ 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);
+ if (timeZoneIsPST())
+ 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);
+ JSClassRelease(nullClass);
+
+ nullDefinition = kJSClassDefinitionEmpty;
+ nullClass = JSClassCreate(&nullDefinition);
+ JSClassRelease(nullClass);
+
+ functionBody = JSStringCreateWithUTF8CString("return 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));
+
+ 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);
+
+ // Verify that creating a constructor for a class with no static functions does not trigger
+ // an assert inside putDirect or lead to a crash during GC. <https://bugs.webkit.org/show_bug.cgi?id=25785>
+ nullDefinition = kJSClassDefinitionEmpty;
+ nullClass = JSClassCreate(&nullDefinition);
+ myConstructor = JSObjectMakeConstructor(context, nullClass, 0);
+ JSClassRelease(nullClass);
+
+ char* scriptUTF8 = createStringWithContentsOfFile(scriptPath);
+ if (!scriptUTF8) {
+ printf("FAIL: Test script could not be loaded.\n");
+ failed = 1;
+ } else {
+ script = JSStringCreateWithUTF8CString(scriptUTF8);
+ result = JSEvaluateScript(context, script, NULL, NULL, 1, &exception);
+ if (result && JSValueIsUndefined(context, result))
+ printf("PASS: Test script executed successfully.\n");
+ else {
+ printf("FAIL: Test script returned unexpected value:\n");
+ JSStringRef exceptionIString = JSValueToStringCopy(context, exception, NULL);
+ CFStringRef exceptionCF = JSStringCopyCFString(kCFAllocatorDefault, exceptionIString);
+ CFShow(exceptionCF);
+ CFRelease(exceptionCF);
+ JSStringRelease(exceptionIString);
+ failed = 1;
+ }
+ JSStringRelease(script);
+ free(scriptUTF8);
+ }
+
+ // Clear out local variables pointing at JSObjectRefs to allow their values to be collected
+ function = NULL;
+ v = NULL;
+ o = NULL;
+ globalObject = NULL;
+ myConstructor = NULL;
+
+ JSStringRelease(jsEmptyIString);
+ JSStringRelease(jsOneIString);
+ JSStringRelease(jsCFIString);
+ JSStringRelease(jsCFEmptyIString);
+ JSStringRelease(jsCFIStringWithCharacters);
+ JSStringRelease(jsCFEmptyIStringWithCharacters);
+ JSStringRelease(goodSyntax);
+ JSStringRelease(badSyntax);
+
+ JSGlobalContextRelease(context);
+ JSClassRelease(globalObjectClass);
+
+ // Test for an infinite prototype chain that used to be created. This test
+ // passes if the call to JSObjectHasProperty() does not hang.
+
+ JSClassDefinition prototypeLoopClassDefinition = kJSClassDefinitionEmpty;
+ prototypeLoopClassDefinition.staticFunctions = globalObject_staticFunctions;
+ JSClassRef prototypeLoopClass = JSClassCreate(&prototypeLoopClassDefinition);
+ JSGlobalContextRef prototypeLoopContext = JSGlobalContextCreateInGroup(NULL, prototypeLoopClass);
+
+ JSStringRef nameProperty = JSStringCreateWithUTF8CString("name");
+ JSObjectHasProperty(prototypeLoopContext, JSContextGetGlobalObject(prototypeLoopContext), nameProperty);
+
+ JSGlobalContextRelease(prototypeLoopContext);
+ JSClassRelease(prototypeLoopClass);
+
+ printf("PASS: Infinite prototype chain does not occur.\n");
+
+ if (checkForCycleInPrototypeChain())
+ printf("PASS: A cycle in a prototype chain can't be created.\n");
+ else {
+ printf("FAIL: A cycle in a prototype chain can be created.\n");
+ failed = true;
+ }
+
+ if (failed) {
+ printf("FAIL: Some tests failed.\n");
+ return 1;
+ }
+
+ printf("PASS: Program exited normally.\n");
+ return 0;
+}
+
+static char* createStringWithContentsOfFile(const char* fileName)
+{
+ char* buffer;
+
+ size_t buffer_size = 0;
+ size_t buffer_capacity = 1024;
+ buffer = (char*)malloc(buffer_capacity);
+
+ FILE* f = fopen(fileName, "r");
+ if (!f) {
+ fprintf(stderr, "Could not open file: %s\n", fileName);
+ return 0;
+ }
+
+ 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'
+ buffer_capacity *= 2;
+ buffer = (char*)realloc(buffer, buffer_capacity);
+ ASSERT(buffer);
+ }
+
+ ASSERT(buffer_size < buffer_capacity);
+ }
+ fclose(f);
+ buffer[buffer_size] = '\0';
+
+ return buffer;
+}
diff --git a/Source/JavaScriptCore/API/tests/testapi.js b/Source/JavaScriptCore/API/tests/testapi.js
new file mode 100644
index 0000000..15c9e50
--- /dev/null
+++ b/Source/JavaScriptCore/API/tests/testapi.js
@@ -0,0 +1,251 @@
+/*
+ * Copyright (C) 2006 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.
+ */
+
+function bludgeonArguments() { if (0) arguments; return function g() {} }
+h = bludgeonArguments();
+gc();
+
+var failed = false;
+function pass(msg)
+{
+ print("PASS: " + msg, "green");
+}
+
+function fail(msg)
+{
+ print("FAIL: " + msg, "red");
+ failed = true;
+}
+
+function shouldBe(a, b)
+{
+ var evalA;
+ try {
+ evalA = eval(a);
+ } catch(e) {
+ evalA = e;
+ }
+
+ if (evalA == b || isNaN(evalA) && typeof evalA == 'number' && isNaN(b) && typeof b == 'number')
+ pass(a + " should be " + b + " and is.");
+ else
+ fail(a + " should be " + b + " but instead is " + evalA + ".");
+}
+
+function shouldThrow(a)
+{
+ var evalA;
+ try {
+ eval(a);
+ } catch(e) {
+ pass(a + " threw: " + e);
+ return;
+ }
+
+ fail(a + " did not throw an exception.");
+}
+
+function globalStaticFunction()
+{
+ return 4;
+}
+
+shouldBe("globalStaticValue", 3);
+shouldBe("globalStaticFunction()", 4);
+
+shouldBe("typeof MyObject", "function"); // our object implements 'call'
+MyObject.cantFind = 1;
+shouldBe("MyObject.cantFind", undefined);
+MyObject.regularType = 1;
+shouldBe("MyObject.regularType", 1);
+MyObject.alwaysOne = 2;
+shouldBe("MyObject.alwaysOne", 1);
+MyObject.cantDelete = 1;
+delete MyObject.cantDelete;
+shouldBe("MyObject.cantDelete", 1);
+shouldBe("delete MyObject.throwOnDelete", "an exception");
+MyObject.cantSet = 1;
+shouldBe("MyObject.cantSet", undefined);
+shouldBe("MyObject.throwOnGet", "an exception");
+shouldBe("MyObject.throwOnSet = 5", "an exception");
+shouldBe("MyObject('throwOnCall')", "an exception");
+shouldBe("new MyObject('throwOnConstruct')", "an exception");
+shouldBe("'throwOnHasInstance' instanceof MyObject", "an exception");
+
+var foundMyPropertyName = false;
+var foundRegularType = false;
+for (var p in MyObject) {
+ if (p == "myPropertyName")
+ foundMyPropertyName = true;
+ if (p == "regularType")
+ foundRegularType = true;
+}
+
+if (foundMyPropertyName)
+ pass("MyObject.myPropertyName was enumerated");
+else
+ fail("MyObject.myPropertyName was not enumerated");
+
+if (foundRegularType)
+ pass("MyObject.regularType was enumerated");
+else
+ fail("MyObject.regularType was not enumerated");
+
+var alwaysOneDescriptor = Object.getOwnPropertyDescriptor(MyObject, "alwaysOne");
+shouldBe('typeof alwaysOneDescriptor', "object");
+shouldBe('alwaysOneDescriptor.value', MyObject.alwaysOne);
+shouldBe('alwaysOneDescriptor.configurable', true);
+shouldBe('alwaysOneDescriptor.enumerable', false); // Actually it is.
+var cantFindDescriptor = Object.getOwnPropertyDescriptor(MyObject, "cantFind");
+shouldBe('typeof cantFindDescriptor', "object");
+shouldBe('cantFindDescriptor.value', MyObject.cantFind);
+shouldBe('cantFindDescriptor.configurable', true);
+shouldBe('cantFindDescriptor.enumerable', false);
+try {
+ // If getOwnPropertyDescriptor() returned an access descriptor, this wouldn't throw.
+ Object.getOwnPropertyDescriptor(MyObject, "throwOnGet");
+} catch (e) {
+ pass("getting property descriptor of throwOnGet threw exception");
+}
+var myPropertyNameDescriptor = Object.getOwnPropertyDescriptor(MyObject, "myPropertyName");
+shouldBe('typeof myPropertyNameDescriptor', "object");
+shouldBe('myPropertyNameDescriptor.value', MyObject.myPropertyName);
+shouldBe('myPropertyNameDescriptor.configurable', true);
+shouldBe('myPropertyNameDescriptor.enumerable', false); // Actually it is.
+try {
+ // if getOwnPropertyDescriptor() returned an access descriptor, this wouldn't throw.
+ Object.getOwnPropertyDescriptor(MyObject, "hasPropertyLie");
+} catch (e) {
+ pass("getting property descriptor of hasPropertyLie threw exception");
+}
+shouldBe('Object.getOwnPropertyDescriptor(MyObject, "doesNotExist")', undefined);
+
+myObject = new MyObject();
+
+shouldBe("delete MyObject.regularType", true);
+shouldBe("MyObject.regularType", undefined);
+shouldBe("MyObject(0)", 1);
+shouldBe("MyObject()", undefined);
+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", 1); // toNumber
+
+shouldBe("typeof MyConstructor", "object");
+constructedObject = new MyConstructor(1);
+shouldBe("typeof constructedObject", "object");
+shouldBe("constructedObject.value", 1);
+shouldBe("myObject instanceof MyObject", true);
+shouldBe("(new Object()) instanceof MyObject", false);
+
+shouldThrow("MyObject.nullGetSet = 1");
+shouldThrow("MyObject.nullGetSet");
+shouldThrow("MyObject.nullCall()");
+shouldThrow("MyObject.hasPropertyLie");
+
+derived = new Derived();
+
+shouldBe("derived instanceof Derived", true);
+shouldBe("derived instanceof Base", true);
+
+// base properties and functions return 1 when called/gotten; derived, 2
+shouldBe("derived.baseProtoDup()", 2);
+shouldBe("derived.baseProto()", 1);
+shouldBe("derived.baseDup", 2);
+shouldBe("derived.baseOnly", 1);
+shouldBe("derived.protoOnly()", 2);
+shouldBe("derived.protoDup", 2);
+shouldBe("derived.derivedOnly", 2)
+
+// base properties throw 1 when set; derived, 2
+shouldBe("derived.baseDup = 0", 2);
+shouldBe("derived.baseOnly = 0", 1);
+shouldBe("derived.derivedOnly = 0", 2)
+shouldBe("derived.protoDup = 0", 2);
+
+derived2 = new Derived2();
+
+shouldBe("derived2 instanceof Derived2", true);
+shouldBe("derived2 instanceof Derived", true);
+shouldBe("derived2 instanceof Base", true);
+
+// base properties and functions return 1 when called/gotten; derived, 2
+shouldBe("derived2.baseProtoDup()", 2);
+shouldBe("derived2.baseProto()", 1);
+shouldBe("derived2.baseDup", 2);
+shouldBe("derived2.baseOnly", 1);
+shouldBe("derived2.protoOnly()", 2);
+shouldBe("derived2.protoDup", 2);
+shouldBe("derived2.derivedOnly", 2)
+
+// base properties throw 1 when set; derived, 2
+shouldBe("derived2.baseDup = 0", 2);
+shouldBe("derived2.baseOnly = 0", 1);
+shouldBe("derived2.derivedOnly = 0", 2)
+shouldBe("derived2.protoDup = 0", 2);
+
+shouldBe('Object.getOwnPropertyDescriptor(derived, "baseProto")', undefined);
+shouldBe('Object.getOwnPropertyDescriptor(derived, "baseProtoDup")', undefined);
+var baseDupDescriptor = Object.getOwnPropertyDescriptor(derived, "baseDup");
+shouldBe('typeof baseDupDescriptor', "object");
+shouldBe('baseDupDescriptor.value', derived.baseDup);
+shouldBe('baseDupDescriptor.configurable', true);
+shouldBe('baseDupDescriptor.enumerable', false);
+var baseOnlyDescriptor = Object.getOwnPropertyDescriptor(derived, "baseOnly");
+shouldBe('typeof baseOnlyDescriptor', "object");
+shouldBe('baseOnlyDescriptor.value', derived.baseOnly);
+shouldBe('baseOnlyDescriptor.configurable', true);
+shouldBe('baseOnlyDescriptor.enumerable', false);
+shouldBe('Object.getOwnPropertyDescriptor(derived, "protoOnly")', undefined);
+var protoDupDescriptor = Object.getOwnPropertyDescriptor(derived, "protoDup");
+shouldBe('typeof protoDupDescriptor', "object");
+shouldBe('protoDupDescriptor.value', derived.protoDup);
+shouldBe('protoDupDescriptor.configurable', true);
+shouldBe('protoDupDescriptor.enumerable', false);
+var derivedOnlyDescriptor = Object.getOwnPropertyDescriptor(derived, "derivedOnly");
+shouldBe('typeof derivedOnlyDescriptor', "object");
+shouldBe('derivedOnlyDescriptor.value', derived.derivedOnly);
+shouldBe('derivedOnlyDescriptor.configurable', true);
+shouldBe('derivedOnlyDescriptor.enumerable', false);
+
+shouldBe("undefined instanceof MyObject", false);
+EvilExceptionObject.hasInstance = function f() { return f(); };
+EvilExceptionObject.__proto__ = undefined;
+shouldThrow("undefined instanceof EvilExceptionObject");
+EvilExceptionObject.hasInstance = function () { return true; };
+shouldBe("undefined instanceof EvilExceptionObject", true);
+
+EvilExceptionObject.toNumber = function f() { return f(); }
+shouldThrow("EvilExceptionObject*5");
+EvilExceptionObject.toStringExplicit = function f() { return f(); }
+shouldThrow("String(EvilExceptionObject)");
+
+shouldBe("EmptyObject", "[object CallbackObject]");
+
+if (failed)
+ throw "Some tests failed";
+