Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit 9d1ef4781fa2b7d35016cb916fcc1be8e5f146ed 0 parents
@jhaynie jhaynie authored
Showing with 150,217 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +3 −0  README
  3. +1 −0  TiCore/.gitignore
  4. +143 −0 TiCore/API/APICast.h
  5. +62 −0 TiCore/API/OpaqueTiString.cpp
  6. +88 −0 TiCore/API/OpaqueTiString.h
  7. +43 −0 TiCore/API/Ti.h
  8. +123 −0 TiCore/API/TiBase.cpp
  9. +151 −0 TiCore/API/TiBase.h
  10. +59 −0 TiCore/API/TiBasePrivate.h
  11. +93 −0 TiCore/API/TiCallbackConstructor.cpp
  12. +67 −0 TiCore/API/TiCallbackConstructor.h
  13. +86 −0 TiCore/API/TiCallbackFunction.cpp
  14. +65 −0 TiCore/API/TiCallbackFunction.h
  15. +48 −0 TiCore/API/TiCallbackObject.cpp
  16. +124 −0 TiCore/API/TiCallbackObject.h
  17. +580 −0 TiCore/API/TiCallbackObjectFunctions.h
  18. +251 −0 TiCore/API/TiClassRef.cpp
  19. +129 −0 TiCore/API/TiClassRef.h
  20. +171 −0 TiCore/API/TiContextRef.cpp
  21. +139 −0 TiCore/API/TiContextRef.h
  22. +60 −0 TiCore/API/TiContextRefPrivate.h
  23. +39 −0 TiCore/API/TiCore.h
  24. +525 −0 TiCore/API/TiObjectRef.cpp
  25. +701 −0 TiCore/API/TiObjectRef.h
  26. +53 −0 TiCore/API/TiProfilerPrivate.cpp
  27. +70 −0 TiCore/API/TiProfilerPrivate.h
  28. +180 −0 TiCore/API/TiRetainPtr.h
  29. +119 −0 TiCore/API/TiStringRef.cpp
  30. +151 −0 TiCore/API/TiStringRef.h
  31. +49 −0 TiCore/API/TiStringRefBSTR.cpp
  32. +69 −0 TiCore/API/TiStringRefBSTR.h
  33. +64 −0 TiCore/API/TiStringRefCF.cpp
  34. +67 −0 TiCore/API/TiStringRefCF.h
  35. +329 −0 TiCore/API/TiValueRef.cpp
  36. +285 −0 TiCore/API/TiValueRef.h
  37. +771 −0 TiCore/API/WebKitAvailability.h
  38. +203 −0 TiCore/API/tests/JSNode.c
  39. +44 −0 TiCore/API/tests/JSNode.h
  40. +130 −0 TiCore/API/tests/JSNodeList.c
  41. +41 −0 TiCore/API/tests/JSNodeList.h
  42. +92 −0 TiCore/API/tests/Node.c
  43. +57 −0 TiCore/API/tests/Node.h
  44. +88 −0 TiCore/API/tests/NodeList.c
  45. +49 −0 TiCore/API/tests/NodeList.h
  46. +133 −0 TiCore/API/tests/minidom.c
  47. +9 −0 TiCore/API/tests/minidom.html
  48. +110 −0 TiCore/API/tests/minidom.js
  49. +1,255 −0 TiCore/API/tests/testapi.c
  50. +174 −0 TiCore/API/tests/testapi.js
  51. +2 −0  TiCore/AUTHORS
  52. +7 −0 TiCore/AllInOneFile.cpp
  53. +488 −0 TiCore/COPYING.LIB
  54. +13,457 −0 TiCore/ChangeLog
  55. +2,271 −0 TiCore/ChangeLog-2002-12-03
  56. +1,483 −0 TiCore/ChangeLog-2003-10-25
  57. +26,221 −0 TiCore/ChangeLog-2007-10-14
  58. +31,482 −0 TiCore/ChangeLog-2008-08-10
  59. +39,978 −0 TiCore/ChangeLog-2009-06-16
  60. +109 −0 TiCore/Configurations/Base.xcconfig
  61. +47 −0 TiCore/Configurations/DebugRelease.xcconfig
  62. +69 −0 TiCore/Configurations/FeatureDefines.xcconfig
  63. +51 −0 TiCore/Configurations/TiCore.xcconfig
  64. +58 −0 TiCore/Configurations/Version.xcconfig
  65. +76 −0 TiCore/DerivedSources.make
  66. +41 −0 TiCore/DerivedSources/TiCore/ArrayPrototype.lut.h
  67. +66 −0 TiCore/DerivedSources/TiCore/DatePrototype.lut.h
  68. +5,130 −0 TiCore/DerivedSources/TiCore/Grammar.cpp
  69. +239 −0 TiCore/DerivedSources/TiCore/Grammar.h
  70. +22 −0 TiCore/DerivedSources/TiCore/JSONObject.lut.h
  71. +54 −0 TiCore/DerivedSources/TiCore/Lexer.lut.h
  72. +38 −0 TiCore/DerivedSources/TiCore/MathObject.lut.h
  73. +25 −0 TiCore/DerivedSources/TiCore/NumberConstructor.lut.h
  74. +41 −0 TiCore/DerivedSources/TiCore/RegExpConstructor.lut.h
  75. +25 −0 TiCore/DerivedSources/TiCore/RegExpObject.lut.h
  76. +55 −0 TiCore/DerivedSources/TiCore/StringPrototype.lut.h
  77. +103 −0 TiCore/DerivedSources/TiCore/chartables.c
  78. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/APICast.h
  79. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/OpaqueTiString.h
  80. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/Ti.h
  81. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/TiBase.h
  82. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/TiContextRef.h
  83. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/TiCore.h
  84. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/TiObjectRef.h
  85. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/TiRetainPtr.h
  86. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/TiStringRef.h
  87. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/TiStringRefCF.h
  88. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/TiValueRef.h
  89. +8 −0 TiCore/ForwardingHeaders/JavaScriptCore/WebKitAvailability.h
  90. +614 −0 TiCore/GNUmakefile.am
  91. +24 −0 TiCore/Info.plist
  92. +202 −0 TiCore/JavaScriptCore.gyp/JavaScriptCore.gyp
  93. +459 −0 TiCore/JavaScriptCore.gypi
  94. +1,965 −0 TiCore/JavaScriptCore.order
  95. +280 −0 TiCore/JavaScriptCore.pri
  96. +68 −0 TiCore/JavaScriptCore.pro
  97. +24 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCore.resources/Info.plist
  98. +95 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCore.sln
  99. +314 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
  100. +47 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.rc
  101. +1,927 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
  102. +11 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreCF.vsprops
  103. +11 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreCFLite.vsprops
  104. +30 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreCommon.vsprops
  105. +53 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreGenerated.vcproj
  106. +25 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCore/TiCoreGenerated.make
  107. +37 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCore/build-generated-files.sh
  108. +83 −0 TiCore/JavaScriptCore.vcproj/JavaScriptCoreSubmit.sln
  109. +33 −0 TiCore/JavaScriptCore.vcproj/TiCore.make
  110. +554 −0 TiCore/JavaScriptCore.vcproj/WTF/WTF.vcproj
  111. +26 −0 TiCore/JavaScriptCore.vcproj/WTF/WTFCommon.vsprops
  112. +335 −0 TiCore/JavaScriptCore.vcproj/jsc/jsc.vcproj
  113. +25 −0 TiCore/JavaScriptCore.vcproj/jsc/jscCommon.vsprops
  114. +449 −0 TiCore/JavaScriptCore.vcproj/testapi/testapi.vcproj
  115. +26 −0 TiCore/JavaScriptCore.vcproj/testapi/testapiCommon.vsprops
  116. +192 −0 TiCore/JavaScriptCoreSources.bkl
  117. +2 −0  TiCore/Makefile
  118. +8 −0 TiCore/THANKS
  119. +415 −0 TiCore/TiCore.exp
  120. +1,377 −0 TiCore/TiCore.xcodeproj/jhaynie.mode1v3
  121. +780 −0 TiCore/TiCore.xcodeproj/jhaynie.pbxuser
  122. +3,783 −0 TiCore/TiCore.xcodeproj/project.pbxproj
  123. +42 −0 TiCore/TiCorePrefix.h
  124. +412 −0 TiCore/assembler/ARMAssembler.cpp
  125. +818 −0 TiCore/assembler/ARMAssembler.h
  126. +1,844 −0 TiCore/assembler/ARMv7Assembler.h
  127. +542 −0 TiCore/assembler/AbstractMacroAssembler.h
  128. +180 −0 TiCore/assembler/AssemblerBuffer.h
  129. +325 −0 TiCore/assembler/AssemblerBufferWithConstantPool.h
  130. +193 −0 TiCore/assembler/CodeLocation.h
  131. +202 −0 TiCore/assembler/LinkBuffer.h
  132. +344 −0 TiCore/assembler/MacroAssembler.h
  133. +101 −0 TiCore/assembler/MacroAssemblerARM.cpp
  134. +862 −0 TiCore/assembler/MacroAssemblerARM.h
Sorry, we could not display the entire diff because too many files (1,751) changed.
1  .gitignore
@@ -0,0 +1 @@
+build
3  README
@@ -0,0 +1,3 @@
+This is a Titanium Mobile fork of WebKit KJS. All changes are made available
+under the Apache Public License (version 2).
+
1  TiCore/.gitignore
@@ -0,0 +1 @@
+build
143 TiCore/API/APICast.h
@@ -0,0 +1,143 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 "TiAPIValueWrapper.h"
+#include "TiGlobalObject.h"
+#include "TiValue.h"
+#include <wtf/Platform.h>
+#include <wtf/UnusedParam.h>
+
+namespace TI {
+ class TiExcState;
+ class PropertyNameArray;
+ class TiGlobalData;
+ class TiObject;
+ class TiValue;
+}
+
+typedef const struct OpaqueTiContextGroup* TiContextGroupRef;
+typedef const struct OpaqueTiContext* TiContextRef;
+typedef struct OpaqueTiContext* TiGlobalContextRef;
+typedef struct OpaqueTiPropertyNameAccumulator* TiPropertyNameAccumulatorRef;
+typedef const struct OpaqueTiValue* TiValueRef;
+typedef struct OpaqueTiValue* TiObjectRef;
+
+/* Opaque typing convenience methods */
+
+inline TI::TiExcState* toJS(TiContextRef c)
+{
+ return reinterpret_cast<TI::TiExcState*>(const_cast<OpaqueTiContext*>(c));
+}
+
+inline TI::TiExcState* toJS(TiGlobalContextRef c)
+{
+ return reinterpret_cast<TI::TiExcState*>(c);
+}
+
+inline TI::TiValue toJS(TI::TiExcState*, TiValueRef v)
+{
+#if USE(JSVALUE32_64)
+ TI::TiCell* jsCell = reinterpret_cast<TI::TiCell*>(const_cast<OpaqueTiValue*>(v));
+ if (!jsCell)
+ return TI::TiValue();
+ if (jsCell->isAPIValueWrapper())
+ return static_cast<TI::TiAPIValueWrapper*>(jsCell)->value();
+ return jsCell;
+#else
+ return TI::TiValue::decode(reinterpret_cast<TI::EncodedTiValue>(const_cast<OpaqueTiValue*>(v)));
+#endif
+}
+
+inline TI::TiObject* toJS(TiObjectRef o)
+{
+ return reinterpret_cast<TI::TiObject*>(o);
+}
+
+inline TI::PropertyNameArray* toJS(TiPropertyNameAccumulatorRef a)
+{
+ return reinterpret_cast<TI::PropertyNameArray*>(a);
+}
+
+inline TI::TiGlobalData* toJS(TiContextGroupRef g)
+{
+ return reinterpret_cast<TI::TiGlobalData*>(const_cast<OpaqueTiContextGroup*>(g));
+}
+
+inline TiValueRef toRef(TI::TiExcState* exec, TI::TiValue v)
+{
+#if USE(JSVALUE32_64)
+ if (!v)
+ return 0;
+ if (!v.isCell())
+ return reinterpret_cast<TiValueRef>(asCell(TI::jsAPIValueWrapper(exec, v)));
+ return reinterpret_cast<TiValueRef>(asCell(v));
+#else
+ UNUSED_PARAM(exec);
+ return reinterpret_cast<TiValueRef>(TI::TiValue::encode(v));
+#endif
+}
+
+inline TiObjectRef toRef(TI::TiObject* o)
+{
+ return reinterpret_cast<TiObjectRef>(o);
+}
+
+inline TiObjectRef toRef(const TI::TiObject* o)
+{
+ return reinterpret_cast<TiObjectRef>(const_cast<TI::TiObject*>(o));
+}
+
+inline TiContextRef toRef(TI::TiExcState* e)
+{
+ return reinterpret_cast<TiContextRef>(e);
+}
+
+inline TiGlobalContextRef toGlobalRef(TI::TiExcState* e)
+{
+ ASSERT(e == e->lexicalGlobalObject()->globalExec());
+ return reinterpret_cast<TiGlobalContextRef>(e);
+}
+
+inline TiPropertyNameAccumulatorRef toRef(TI::PropertyNameArray* l)
+{
+ return reinterpret_cast<TiPropertyNameAccumulatorRef>(l);
+}
+
+inline TiContextGroupRef toRef(TI::TiGlobalData* g)
+{
+ return reinterpret_cast<TiContextGroupRef>(g);
+}
+
+#endif // APICast_h
62 TiCore/API/OpaqueTiString.cpp
@@ -0,0 +1,62 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 "OpaqueTiString.h"
+
+#include <interpreter/CallFrame.h>
+#include <runtime/TiGlobalObject.h>
+#include <runtime/Identifier.h>
+
+using namespace TI;
+
+PassRefPtr<OpaqueTiString> OpaqueTiString::create(const UString& ustring)
+{
+ if (!ustring.isNull())
+ return adoptRef(new OpaqueTiString(ustring.data(), ustring.size()));
+ return 0;
+}
+
+UString OpaqueTiString::ustring() const
+{
+ if (this && m_characters)
+ return UString(m_characters, m_length, true);
+ return UString::null();
+}
+
+Identifier OpaqueTiString::identifier(TiGlobalData* globalData) const
+{
+ if (!this || !m_characters)
+ return Identifier(globalData, static_cast<const char*>(0));
+
+ return Identifier(globalData, m_characters, m_length);
+}
88 TiCore/API/OpaqueTiString.h
@@ -0,0 +1,88 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 OpaqueTiString_h
+#define OpaqueTiString_h
+
+#include <runtime/UString.h>
+
+namespace TI {
+ class Identifier;
+ class TiGlobalData;
+}
+
+struct OpaqueTiString : public ThreadSafeShared<OpaqueTiString> {
+
+ static PassRefPtr<OpaqueTiString> create() // null
+ {
+ return adoptRef(new OpaqueTiString);
+ }
+
+ static PassRefPtr<OpaqueTiString> create(const UChar* characters, unsigned length)
+ {
+ return adoptRef(new OpaqueTiString(characters, length));
+ }
+
+ static PassRefPtr<OpaqueTiString> create(const TI::UString&);
+
+ UChar* characters() { return this ? m_characters : 0; }
+ unsigned length() { return this ? m_length : 0; }
+
+ TI::UString ustring() const;
+ TI::Identifier identifier(TI::TiGlobalData*) const;
+
+private:
+ friend class WTI::ThreadSafeShared<OpaqueTiString>;
+
+ OpaqueTiString()
+ : m_characters(0)
+ , m_length(0)
+ {
+ }
+
+ OpaqueTiString(const UChar* characters, unsigned length)
+ : m_length(length)
+ {
+ m_characters = new UChar[length];
+ memcpy(m_characters, characters, length * sizeof(UChar));
+ }
+
+ ~OpaqueTiString()
+ {
+ delete[] m_characters;
+ }
+
+ UChar* m_characters;
+ unsigned m_length;
+};
+
+#endif
43 TiCore/API/Ti.h
@@ -0,0 +1,43 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 Ti_h
+#define Ti_h
+
+#include <TiCore/TiBase.h>
+#include <TiCore/TiContextRef.h>
+#include <TiCore/TiStringRef.h>
+#include <TiCore/TiObjectRef.h>
+#include <TiCore/TiValueRef.h>
+
+#endif /* Ti_h */
123 TiCore/API/TiBase.cpp
@@ -0,0 +1,123 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 "TiBase.h"
+#include "TiBasePrivate.h"
+
+#include "APICast.h"
+#include "Completion.h"
+#include "OpaqueTiString.h"
+#include "SourceCode.h"
+#include <interpreter/CallFrame.h>
+#include <runtime/InitializeThreading.h>
+#include <runtime/Completion.h>
+#include <runtime/TiGlobalObject.h>
+#include <runtime/TiLock.h>
+#include <runtime/TiObject.h>
+
+using namespace TI;
+
+TiValueRef TiEvalScript(TiContextRef ctx, TiStringRef script, TiObjectRef thisObject, TiStringRef sourceURL, int startingLineNumber, TiValueRef* exception)
+{
+ TiExcState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ TiLock lock(exec);
+
+ TiObject* jsThisObject = toJS(thisObject);
+
+ // evaluate sets "this" to the global object if it is NULL
+ TiGlobalObject* 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 TiCheckScriptSyntax(TiContextRef ctx, TiStringRef script, TiStringRef sourceURL, int startingLineNumber, TiValueRef* exception)
+{
+ TiExcState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ TiLock lock(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 TiGarbageCollect(TiContextRef 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;
+
+ TiExcState* exec = toJS(ctx);
+ TiGlobalData& globalData = exec->globalData();
+
+ TiLock lock(globalData.isSharedInstance ? LockForReal : SilenceAssertionsOnly);
+
+ if (!globalData.heap.isBusy())
+ globalData.heap.collect();
+
+ // FIXME: Perhaps we should trigger a second mark and sweep
+ // once the garbage collector is done if this is called when
+ // the collector is busy.
+}
+
+void JSReportExtraMemoryCost(TiContextRef ctx, size_t size)
+{
+ TiExcState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ TiLock lock(exec);
+
+ exec->globalData().heap.reportExtraMemoryCost(size);
+}
151 TiCore/API/TiBase.h
@@ -0,0 +1,151 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 TiBase_h
+#define TiBase_h
+
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+
+/* Ti engine interface */
+
+/*! @typedef TiContextGroupRef A group that associates Ti contexts with one another. Contexts in the same group may share and exchange Ti objects. */
+typedef const struct OpaqueTiContextGroup* TiContextGroupRef;
+
+/*! @typedef TiContextRef A Ti execution context. Holds the global object and other execution state. */
+typedef const struct OpaqueTiContext* TiContextRef;
+
+/*! @typedef TiGlobalContextRef A global Ti execution context. A TiGlobalContext is a TiContext. */
+typedef struct OpaqueTiContext* TiGlobalContextRef;
+
+/*! @typedef TiStringRef A UTF16 character buffer. The fundamental string representation in Ti. */
+typedef struct OpaqueTiString* TiStringRef;
+
+/*! @typedef TiClassRef A Ti class. Used with TiObjectMake to construct objects with custom behavior. */
+typedef struct OpaqueTiClass* TiClassRef;
+
+/*! @typedef TiPropertyNameArrayRef An array of Ti property names. */
+typedef struct OpaqueTiPropertyNameArray* TiPropertyNameArrayRef;
+
+/*! @typedef TiPropertyNameAccumulatorRef An ordered set used to collect the names of a Ti object's properties. */
+typedef struct OpaqueTiPropertyNameAccumulator* TiPropertyNameAccumulatorRef;
+
+
+/* Ti data types */
+
+/*! @typedef TiValueRef A Ti value. The base type for all Ti values, and polymorphic functions on them. */
+typedef const struct OpaqueTiValue* TiValueRef;
+
+/*! @typedef TiObjectRef A Ti object. A TiObject is a TiValue. */
+typedef struct OpaqueTiValue* TiObjectRef;
+
+/* Ti symbol exports */
+
+#undef JS_EXPORT
+#if defined(BUILDING_WX__)
+ #define JS_EXPORT
+#elif defined(__GNUC__) && !defined(__CC_ARM) && !defined(__ARMCC__)
+ #define JS_EXPORT __attribute__((visibility("default")))
+#elif defined(_WIN32_WCE)
+ #if defined(JS_BUILDING_JS)
+ #define JS_EXPORT __declspec(dllexport)
+ #elif defined(JS_IMPORT_JS)
+ #define JS_EXPORT __declspec(dllimport)
+ #else
+ #define JS_EXPORT
+ #endif
+#elif defined(WIN32) || defined(_WIN32)
+ /*
+ * TODO: Export symbols with JS_EXPORT when using MSVC.
+ * See http://bugs.webkit.org/show_bug.cgi?id=16227
+ */
+ #if defined(BUILDING_TiCore) || 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 TiEvalScript
+@abstract Evaluates a string of Ti.
+@param ctx The execution context to use.
+@param script A TiString 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 TiString 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 TiValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.
+@result The TiValue that results from evaluating script, or NULL if an exception is thrown.
+*/
+JS_EXPORT TiValueRef TiEvalScript(TiContextRef ctx, TiStringRef script, TiObjectRef thisObject, TiStringRef sourceURL, int startingLineNumber, TiValueRef* exception);
+
+/*!
+@function TiCheckScriptSyntax
+@abstract Checks for syntax errors in a string of Ti.
+@param ctx The execution context to use.
+@param script A TiString containing the script to check for syntax errors.
+@param sourceURL A TiString 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 TiValueRef 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 TiCheckScriptSyntax(TiContextRef ctx, TiStringRef script, TiStringRef sourceURL, int startingLineNumber, TiValueRef* exception);
+
+/*!
+@function TiGarbageCollect
+@abstract Performs a Ti garbage collection.
+@param ctx The execution context to use.
+@discussion Ti values that are on the machine stack, in a register,
+ protected by TiValueProtect, set as the global object of an execution context,
+ or reachable from any such value will not be collected.
+
+ During Ti execution, you are not required to call this function; the
+ Ti engine will garbage collect as needed. Ti values created
+ within a context group are automatically destroyed when the last reference
+ to the context group is released.
+*/
+JS_EXPORT void TiGarbageCollect(TiContextRef ctx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TiBase_h */
59 TiCore/API/TiBasePrivate.h
@@ -0,0 +1,59 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 TiBasePrivate_h
+#define TiBasePrivate_h
+
+#include <TiCore/TiBase.h>
+#include <TiCore/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(TiContextRef ctx, size_t size) AVAILABLE_IN_WEBKIT_VERSION_4_0;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TiBasePrivate_h */
93 TiCore/API/TiCallbackConstructor.cpp
@@ -0,0 +1,93 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 "TiCallbackConstructor.h"
+
+#include "APICast.h"
+#include <runtime/TiGlobalObject.h>
+#include <runtime/TiLock.h>
+#include <runtime/ObjectPrototype.h>
+#include <wtf/Vector.h>
+
+namespace TI {
+
+const ClassInfo TiCallbackConstructor::info = { "CallbackConstructor", 0, 0, 0 };
+
+TiCallbackConstructor::TiCallbackConstructor(NonNullPassRefPtr<Structure> structure, TiClassRef jsClass, TiObjectCallAsConstructorCallback callback)
+ : TiObject(structure)
+ , m_class(jsClass)
+ , m_callback(callback)
+{
+ if (m_class)
+ TiClassRetain(jsClass);
+}
+
+TiCallbackConstructor::~TiCallbackConstructor()
+{
+ if (m_class)
+ TiClassRelease(m_class);
+}
+
+static TiObject* constructTiCallback(TiExcState* exec, TiObject* constructor, const ArgList& args)
+{
+ TiContextRef ctx = toRef(exec);
+ TiObjectRef constructorRef = toRef(constructor);
+
+ TiObjectCallAsConstructorCallback callback = static_cast<TiCallbackConstructor*>(constructor)->callback();
+ if (callback) {
+ int argumentCount = static_cast<int>(args.size());
+ Vector<TiValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(exec, args.at(i));
+
+ TiValueRef exception = 0;
+ TiObjectRef result;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ result = callback(ctx, constructorRef, argumentCount, arguments.data(), &exception);
+ }
+ if (exception)
+ exec->setException(toJS(exec, exception));
+ return toJS(result);
+ }
+
+ return toJS(TiObjectMake(ctx, static_cast<TiCallbackConstructor*>(constructor)->classRef(), 0));
+}
+
+ConstructType TiCallbackConstructor::getConstructData(ConstructData& constructData)
+{
+ constructData.native.function = constructTiCallback;
+ return ConstructTypeHost;
+}
+
+} // namespace TI
67 TiCore/API/TiCallbackConstructor.h
@@ -0,0 +1,67 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 TiCallbackConstructor_h
+#define TiCallbackConstructor_h
+
+#include "TiObjectRef.h"
+#include <runtime/TiObject.h>
+
+namespace TI {
+
+class TiCallbackConstructor : public TiObject {
+public:
+ TiCallbackConstructor(NonNullPassRefPtr<Structure>, TiClassRef, TiObjectCallAsConstructorCallback);
+ virtual ~TiCallbackConstructor();
+ TiClassRef classRef() const { return m_class; }
+ TiObjectCallAsConstructorCallback callback() const { return m_callback; }
+ static const ClassInfo info;
+
+ static PassRefPtr<Structure> createStructure(TiValue proto)
+ {
+ return Structure::create(proto, TypeInfo(ObjectType, StructureFlags));
+ }
+
+protected:
+ static const unsigned StructureFlags = ImplementsHasInstance | TiObject::StructureFlags;
+
+private:
+ virtual ConstructType getConstructData(ConstructData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ TiClassRef m_class;
+ TiObjectCallAsConstructorCallback m_callback;
+};
+
+} // namespace TI
+
+#endif // TiCallbackConstructor_h
86 TiCore/API/TiCallbackFunction.cpp
@@ -0,0 +1,86 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 <wtf/Platform.h>
+#include "TiCallbackFunction.h"
+
+#include "APICast.h"
+#include "CodeBlock.h"
+#include "TiFunction.h"
+#include "FunctionPrototype.h"
+#include <runtime/TiGlobalObject.h>
+#include <runtime/TiLock.h>
+#include <wtf/Vector.h>
+
+namespace TI {
+
+ASSERT_CLASS_FITS_IN_CELL(TiCallbackFunction);
+
+const ClassInfo TiCallbackFunction::info = { "CallbackFunction", &InternalFunction::info, 0, 0 };
+
+TiCallbackFunction::TiCallbackFunction(TiExcState* exec, TiObjectCallAsFunctionCallback callback, const Identifier& name)
+ : InternalFunction(&exec->globalData(), exec->lexicalGlobalObject()->callbackFunctionStructure(), name)
+ , m_callback(callback)
+{
+}
+
+TiValue TiCallbackFunction::call(TiExcState* exec, TiObject* functionObject, TiValue thisValue, const ArgList& args)
+{
+ TiContextRef execRef = toRef(exec);
+ TiObjectRef functionRef = toRef(functionObject);
+ TiObjectRef thisObjRef = toRef(thisValue.toThisObject(exec));
+
+ int argumentCount = static_cast<int>(args.size());
+ Vector<TiValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(exec, args.at(i));
+
+ TiValueRef exception = 0;
+ TiValueRef result;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ result = static_cast<TiCallbackFunction*>(functionObject)->m_callback(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception);
+ }
+ if (exception)
+ exec->setException(toJS(exec, exception));
+
+ return toJS(exec, result);
+}
+
+CallType TiCallbackFunction::getCallData(CallData& callData)
+{
+ callData.native.function = call;
+ return CallTypeHost;
+}
+
+} // namespace TI
65 TiCore/API/TiCallbackFunction.h
@@ -0,0 +1,65 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 TiCallbackFunction_h
+#define TiCallbackFunction_h
+
+#include "InternalFunction.h"
+#include "TiObjectRef.h"
+
+namespace TI {
+
+class TiCallbackFunction : public InternalFunction {
+public:
+ TiCallbackFunction(TiExcState*, TiObjectCallAsFunctionCallback, 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(TiValue proto)
+ {
+ return Structure::create(proto, TypeInfo(ObjectType, StructureFlags));
+ }
+
+private:
+ virtual CallType getCallData(CallData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ static TiValue JSC_HOST_CALL call(TiExcState*, TiObject*, TiValue, const ArgList&);
+
+ TiObjectCallAsFunctionCallback m_callback;
+};
+
+} // namespace TI
+
+#endif // TiCallbackFunction_h
48 TiCore/API/TiCallbackObject.cpp
@@ -0,0 +1,48 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 "TiCallbackObject.h"
+
+#include "Collector.h"
+
+namespace TI {
+
+ASSERT_CLASS_FITS_IN_CELL(TiCallbackObject<TiObject>);
+ASSERT_CLASS_FITS_IN_CELL(TiCallbackObject<TiGlobalObject>);
+
+// Define the two types of TiCallbackObjects we support.
+template <> const ClassInfo TiCallbackObject<TiObject>::info = { "CallbackObject", 0, 0, 0 };
+template <> const ClassInfo TiCallbackObject<TiGlobalObject>::info = { "CallbackGlobalObject", 0, 0, 0 };
+
+} // namespace TI
124 TiCore/API/TiCallbackObject.h
@@ -0,0 +1,124 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * 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 TiCallbackObject_h
+#define TiCallbackObject_h
+
+#include "TiObjectRef.h"
+#include "TiValueRef.h"
+#include "TiObject.h"
+
+namespace TI {
+
+template <class Base>
+class TiCallbackObject : public Base {
+public:
+ TiCallbackObject(TiExcState*, NonNullPassRefPtr<Structure>, TiClassRef, void* data);
+ TiCallbackObject(TiClassRef);
+ virtual ~TiCallbackObject();
+
+ void setPrivate(void* data);
+ void* getPrivate();
+
+ static const ClassInfo info;
+
+ TiClassRef classRef() const { return m_callbackObjectData->jsClass; }
+ bool inherits(TiClassRef) const;
+
+ static PassRefPtr<Structure> createStructure(TiValue proto)
+ {
+ return Structure::create(proto, TypeInfo(ObjectType, StructureFlags));
+ }
+
+protected:
+ static const unsigned StructureFlags = OverridesGetOwnPropertySlot | ImplementsHasInstance | OverridesHasInstance | OverridesMarkChildren | OverridesGetPropertyNames | Base::StructureFlags;
+
+private:
+ virtual UString className() const;
+
+ virtual bool getOwnPropertySlot(TiExcState*, const Identifier&, PropertySlot&);
+ virtual bool getOwnPropertySlot(TiExcState*, unsigned, PropertySlot&);
+
+ virtual void put(TiExcState*, const Identifier&, TiValue, PutPropertySlot&);
+
+ virtual bool deleteProperty(TiExcState*, const Identifier&);
+ virtual bool deleteProperty(TiExcState*, unsigned);
+
+ virtual bool hasInstance(TiExcState* exec, TiValue value, TiValue proto);
+
+ virtual void getOwnPropertyNames(TiExcState*, PropertyNameArray&);
+
+ virtual double toNumber(TiExcState*) const;
+ virtual UString toString(TiExcState*) const;
+
+ virtual ConstructType getConstructData(ConstructData&);
+ virtual CallType getCallData(CallData&);
+ virtual const ClassInfo* classInfo() const { return &info; }
+
+ void init(TiExcState*);
+
+ static TiCallbackObject* asCallbackObject(TiValue);
+
+ static TiValue JSC_HOST_CALL call(TiExcState*, TiObject* functionObject, TiValue thisValue, const ArgList&);
+ static TiObject* construct(TiExcState*, TiObject* constructor, const ArgList&);
+
+ static TiValue staticValueGetter(TiExcState*, const Identifier&, const PropertySlot&);
+ static TiValue staticFunctionGetter(TiExcState*, const Identifier&, const PropertySlot&);
+ static TiValue callbackGetter(TiExcState*, const Identifier&, const PropertySlot&);
+
+ struct TiCallbackObjectData {
+ TiCallbackObjectData(void* privateData, TiClassRef jsClass)
+ : privateData(privateData)
+ , jsClass(jsClass)
+ {
+ TiClassRetain(jsClass);
+ }
+
+ ~TiCallbackObjectData()
+ {
+ TiClassRelease(jsClass);
+ }
+
+ void* privateData;
+ TiClassRef jsClass;
+ };
+
+ OwnPtr<TiCallbackObjectData> m_callbackObjectData;
+};
+
+} // namespace TI
+
+// include the actual template class implementation
+#include "TiCallbackObjectFunctions.h"
+
+#endif // TiCallbackObject_h
580 TiCore/API/TiCallbackObjectFunctions.h
@@ -0,0 +1,580 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 "APICast.h"
+#include "Error.h"
+#include "TiCallbackFunction.h"
+#include "TiClassRef.h"
+#include "TiGlobalObject.h"
+#include "TiLock.h"
+#include "TiObjectRef.h"
+#include "TiString.h"
+#include "TiStringRef.h"
+#include "OpaqueTiString.h"
+#include "PropertyNameArray.h"
+#include <wtf/Vector.h>
+
+namespace TI {
+
+template <class Base>
+inline TiCallbackObject<Base>* TiCallbackObject<Base>::asCallbackObject(TiValue value)
+{
+ ASSERT(asObject(value)->inherits(&info));
+ return static_cast<TiCallbackObject*>(asObject(value));
+}
+
+template <class Base>
+TiCallbackObject<Base>::TiCallbackObject(TiExcState* exec, NonNullPassRefPtr<Structure> structure, TiClassRef jsClass, void* data)
+ : Base(structure)
+ , m_callbackObjectData(new TiCallbackObjectData(data, jsClass))
+{
+ init(exec);
+}
+
+// Global object constructor.
+// FIXME: Move this into a separate TiGlobalCallbackObject class derived from this one.
+template <class Base>
+TiCallbackObject<Base>::TiCallbackObject(TiClassRef jsClass)
+ : Base()
+ , m_callbackObjectData(new TiCallbackObjectData(0, jsClass))
+{
+ ASSERT(Base::isGlobalObject());
+ init(static_cast<TiGlobalObject*>(this)->globalExec());
+}
+
+template <class Base>
+void TiCallbackObject<Base>::init(TiExcState* exec)
+{
+ ASSERT(exec);
+
+ Vector<TiObjectInitializeCallback, 16> initRoutines;
+ TiClassRef jsClass = classRef();
+ do {
+ if (TiObjectInitializeCallback 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--) {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ TiObjectInitializeCallback initialize = initRoutines[i];
+ initialize(toRef(exec), toRef(this));
+ }
+}
+
+template <class Base>
+TiCallbackObject<Base>::~TiCallbackObject()
+{
+ TiObjectRef thisRef = toRef(this);
+
+ for (TiClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (TiObjectFinalizeCallback finalize = jsClass->finalize)
+ finalize(thisRef);
+}
+
+template <class Base>
+UString TiCallbackObject<Base>::className() const
+{
+ UString thisClassName = classRef()->className();
+ if (!thisClassName.isEmpty())
+ return thisClassName;
+
+ return Base::className();
+}
+
+template <class Base>
+bool TiCallbackObject<Base>::getOwnPropertySlot(TiExcState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ TiContextRef ctx = toRef(exec);
+ TiObjectRef thisRef = toRef(this);
+ RefPtr<OpaqueTiString> propertyNameRef;
+
+ for (TiClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ // optional optimization to bypass getProperty in cases when we only need to know if the property exists
+ if (TiObjectHasPropertyCallback hasProperty = jsClass->hasProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueTiString::create(propertyName.ustring());
+ TiLock::DropAllLocks dropAllLocks(exec);
+ if (hasProperty(ctx, thisRef, propertyNameRef.get())) {
+ slot.setCustom(this, callbackGetter);
+ return true;
+ }
+ } else if (TiObjectGetPropertyCallback getProperty = jsClass->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueTiString::create(propertyName.ustring());
+ TiValueRef exception = 0;
+ TiValueRef value;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ value = getProperty(ctx, thisRef, propertyNameRef.get(), &exception);
+ }
+ exec->setException(toJS(exec, exception));
+ if (value) {
+ slot.setValue(toJS(exec, value));
+ return true;
+ }
+ if (exception) {
+ slot.setValue(jsUndefined());
+ return true;
+ }
+ }
+
+ if (OpaqueTiClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (staticValues->contains(propertyName.ustring().rep())) {
+ slot.setCustom(this, staticValueGetter);
+ return true;
+ }
+ }
+
+ if (OpaqueTiClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (staticFunctions->contains(propertyName.ustring().rep())) {
+ slot.setCustom(this, staticFunctionGetter);
+ return true;
+ }
+ }
+ }
+
+ return Base::getOwnPropertySlot(exec, propertyName, slot);
+}
+
+template <class Base>
+bool TiCallbackObject<Base>::getOwnPropertySlot(TiExcState* exec, unsigned propertyName, PropertySlot& slot)
+{
+ return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
+}
+
+template <class Base>
+void TiCallbackObject<Base>::put(TiExcState* exec, const Identifier& propertyName, TiValue value, PutPropertySlot& slot)
+{
+ TiContextRef ctx = toRef(exec);
+ TiObjectRef thisRef = toRef(this);
+ RefPtr<OpaqueTiString> propertyNameRef;
+ TiValueRef valueRef = toRef(exec, value);
+
+ for (TiClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (TiObjectSetPropertyCallback setProperty = jsClass->setProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueTiString::create(propertyName.ustring());
+ TiValueRef exception = 0;
+ bool result;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
+ }
+ exec->setException(toJS(exec, exception));
+ if (result || exception)
+ return;
+ }
+
+ if (OpaqueTiClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
+ if (entry->attributes & kTiPropertyAttributeReadOnly)
+ return;
+ if (TiObjectSetPropertyCallback setProperty = entry->setProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueTiString::create(propertyName.ustring());
+ TiValueRef exception = 0;
+ bool result;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ result = setProperty(ctx, thisRef, propertyNameRef.get(), valueRef, &exception);
+ }
+ exec->setException(toJS(exec, exception));
+ if (result || exception)
+ return;
+ } else
+ throwError(exec, ReferenceError, "Attempt to set a property that is not settable.");
+ }
+ }
+
+ if (OpaqueTiClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
+ if (entry->attributes & kTiPropertyAttributeReadOnly)
+ return;
+ TiCallbackObject<Base>::putDirect(propertyName, value); // put as override property
+ return;
+ }
+ }
+ }
+
+ return Base::put(exec, propertyName, value, slot);
+}
+
+template <class Base>
+bool TiCallbackObject<Base>::deleteProperty(TiExcState* exec, const Identifier& propertyName)
+{
+ TiContextRef ctx = toRef(exec);
+ TiObjectRef thisRef = toRef(this);
+ RefPtr<OpaqueTiString> propertyNameRef;
+
+ for (TiClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (TiObjectDeletePropertyCallback deleteProperty = jsClass->deleteProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueTiString::create(propertyName.ustring());
+ TiValueRef exception = 0;
+ bool result;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ result = deleteProperty(ctx, thisRef, propertyNameRef.get(), &exception);
+ }
+ exec->setException(toJS(exec, exception));
+ if (result || exception)
+ return true;
+ }
+
+ if (OpaqueTiClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep())) {
+ if (entry->attributes & kTiPropertyAttributeDontDelete)
+ return false;
+ return true;
+ }
+ }
+
+ if (OpaqueTiClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
+ if (entry->attributes & kTiPropertyAttributeDontDelete)
+ return false;
+ return true;
+ }
+ }
+ }
+
+ return Base::deleteProperty(exec, propertyName);
+}
+
+template <class Base>
+bool TiCallbackObject<Base>::deleteProperty(TiExcState* exec, unsigned propertyName)
+{
+ return deleteProperty(exec, Identifier::from(exec, propertyName));
+}
+
+template <class Base>
+ConstructType TiCallbackObject<Base>::getConstructData(ConstructData& constructData)
+{
+ for (TiClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (jsClass->callAsConstructor) {
+ constructData.native.function = construct;
+ return ConstructTypeHost;
+ }
+ }
+ return ConstructTypeNone;
+}
+
+template <class Base>
+TiObject* TiCallbackObject<Base>::construct(TiExcState* exec, TiObject* constructor, const ArgList& args)
+{
+ TiContextRef execRef = toRef(exec);
+ TiObjectRef constructorRef = toRef(constructor);
+
+ for (TiClassRef jsClass = static_cast<TiCallbackObject<Base>*>(constructor)->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (TiObjectCallAsConstructorCallback callAsConstructor = jsClass->callAsConstructor) {
+ int argumentCount = static_cast<int>(args.size());
+ Vector<TiValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(exec, args.at(i));
+ TiValueRef exception = 0;
+ TiObject* result;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ result = toJS(callAsConstructor(execRef, constructorRef, argumentCount, arguments.data(), &exception));
+ }
+ exec->setException(toJS(exec, exception));
+ return result;
+ }
+ }
+
+ ASSERT_NOT_REACHED(); // getConstructData should prevent us from reaching here
+ return 0;
+}
+
+template <class Base>
+bool TiCallbackObject<Base>::hasInstance(TiExcState* exec, TiValue value, TiValue)
+{
+ TiContextRef execRef = toRef(exec);
+ TiObjectRef thisRef = toRef(this);
+
+ for (TiClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (TiObjectHasInstanceCallback hasInstance = jsClass->hasInstance) {
+ TiValueRef valueRef = toRef(exec, value);
+ TiValueRef exception = 0;
+ bool result;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ result = hasInstance(execRef, thisRef, valueRef, &exception);
+ }
+ exec->setException(toJS(exec, exception));
+ return result;
+ }
+ }
+ return false;
+}
+
+template <class Base>
+CallType TiCallbackObject<Base>::getCallData(CallData& callData)
+{
+ for (TiClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (jsClass->callAsFunction) {
+ callData.native.function = call;
+ return CallTypeHost;
+ }
+ }
+ return CallTypeNone;
+}
+
+template <class Base>
+TiValue TiCallbackObject<Base>::call(TiExcState* exec, TiObject* functionObject, TiValue thisValue, const ArgList& args)
+{
+ TiContextRef execRef = toRef(exec);
+ TiObjectRef functionRef = toRef(functionObject);
+ TiObjectRef thisObjRef = toRef(thisValue.toThisObject(exec));
+
+ for (TiClassRef jsClass = static_cast<TiCallbackObject<Base>*>(functionObject)->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (TiObjectCallAsFunctionCallback callAsFunction = jsClass->callAsFunction) {
+ int argumentCount = static_cast<int>(args.size());
+ Vector<TiValueRef, 16> arguments(argumentCount);
+ for (int i = 0; i < argumentCount; i++)
+ arguments[i] = toRef(exec, args.at(i));
+ TiValueRef exception = 0;
+ TiValue result;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ result = toJS(exec, callAsFunction(execRef, functionRef, thisObjRef, argumentCount, arguments.data(), &exception));
+ }
+ exec->setException(toJS(exec, exception));
+ return result;
+ }
+ }
+
+ ASSERT_NOT_REACHED(); // getCallData should prevent us from reaching here
+ return TiValue();
+}
+
+template <class Base>
+void TiCallbackObject<Base>::getOwnPropertyNames(TiExcState* exec, PropertyNameArray& propertyNames)
+{
+ TiContextRef execRef = toRef(exec);
+ TiObjectRef thisRef = toRef(this);
+
+ for (TiClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (TiObjectGetPropertyNamesCallback getPropertyNames = jsClass->getPropertyNames) {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ getPropertyNames(execRef, thisRef, toRef(&propertyNames));
+ }
+
+ if (OpaqueTiClassStaticValuesTable* staticValues = jsClass->staticValues(exec)) {
+ typedef OpaqueTiClassStaticValuesTable::const_iterator iterator;
+ iterator end = staticValues->end();
+ for (iterator it = staticValues->begin(); it != end; ++it) {
+ UString::Rep* name = it->first.get();
+ StaticValueEntry* entry = it->second;
+ if (entry->getProperty && !(entry->attributes & kTiPropertyAttributeDontEnum))
+ propertyNames.add(Identifier(exec, name));
+ }
+ }
+
+ if (OpaqueTiClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ typedef OpaqueTiClassStaticFunctionsTable::const_iterator iterator;
+ iterator end = staticFunctions->end();
+ for (iterator it = staticFunctions->begin(); it != end; ++it) {
+ UString::Rep* name = it->first.get();
+ StaticFunctionEntry* entry = it->second;
+ if (!(entry->attributes & kTiPropertyAttributeDontEnum))
+ propertyNames.add(Identifier(exec, name));
+ }
+ }
+ }
+
+ Base::getOwnPropertyNames(exec, propertyNames);
+}
+
+template <class Base>
+double TiCallbackObject<Base>::toNumber(TiExcState* 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;
+ TiContextRef ctx = toRef(exec);
+ TiObjectRef thisRef = toRef(this);
+
+ for (TiClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (TiObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
+ TiValueRef exception = 0;
+ TiValueRef value;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ value = convertToType(ctx, thisRef, kTITypeNumber, &exception);
+ }
+ if (exception) {
+ exec->setException(toJS(exec, exception));
+ return 0;
+ }
+
+ double dValue;
+ return toJS(exec, value).getNumber(dValue) ? dValue : NaN;
+ }
+
+ return Base::toNumber(exec);
+}
+
+template <class Base>
+UString TiCallbackObject<Base>::toString(TiExcState* exec) const
+{
+ TiContextRef ctx = toRef(exec);
+ TiObjectRef thisRef = toRef(this);
+
+ for (TiClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (TiObjectConvertToTypeCallback convertToType = jsClass->convertToType) {
+ TiValueRef exception = 0;
+ TiValueRef value;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ value = convertToType(ctx, thisRef, kTITypeString, &exception);
+ }
+ if (exception) {
+ exec->setException(toJS(exec, exception));
+ return "";
+ }
+ return toJS(exec, value).getString();
+ }
+
+ return Base::toString(exec);
+}
+
+template <class Base>
+void TiCallbackObject<Base>::setPrivate(void* data)
+{
+ m_callbackObjectData->privateData = data;
+}
+
+template <class Base>
+void* TiCallbackObject<Base>::getPrivate()
+{
+ return m_callbackObjectData->privateData;
+}
+
+template <class Base>
+bool TiCallbackObject<Base>::inherits(TiClassRef c) const
+{
+ for (TiClassRef jsClass = classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (jsClass == c)
+ return true;
+
+ return false;
+}
+
+template <class Base>
+TiValue TiCallbackObject<Base>::staticValueGetter(TiExcState* exec, const Identifier& propertyName, const PropertySlot& slot)
+{
+ TiCallbackObject* thisObj = asCallbackObject(slot.slotBase());
+
+ TiObjectRef thisRef = toRef(thisObj);
+ RefPtr<OpaqueTiString> propertyNameRef;
+
+ for (TiClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (OpaqueTiClassStaticValuesTable* staticValues = jsClass->staticValues(exec))
+ if (StaticValueEntry* entry = staticValues->get(propertyName.ustring().rep()))
+ if (TiObjectGetPropertyCallback getProperty = entry->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueTiString::create(propertyName.ustring());
+ TiValueRef exception = 0;
+ TiValueRef value;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
+ }
+ exec->setException(toJS(exec, exception));
+ if (value)
+ return toJS(exec, value);
+ if (exception)
+ return jsUndefined();
+ }
+
+ return throwError(exec, ReferenceError, "Static value property defined with NULL getProperty callback.");
+}
+
+template <class Base>
+TiValue TiCallbackObject<Base>::staticFunctionGetter(TiExcState* exec, const Identifier& propertyName, const PropertySlot& slot)
+{
+ TiCallbackObject* thisObj = asCallbackObject(slot.slotBase());
+
+ // Check for cached or override property.
+ PropertySlot slot2(thisObj);
+ if (thisObj->Base::getOwnPropertySlot(exec, propertyName, slot2))
+ return slot2.getValue(exec, propertyName);
+
+ for (TiClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass) {
+ if (OpaqueTiClassStaticFunctionsTable* staticFunctions = jsClass->staticFunctions(exec)) {
+ if (StaticFunctionEntry* entry = staticFunctions->get(propertyName.ustring().rep())) {
+ if (TiObjectCallAsFunctionCallback callAsFunction = entry->callAsFunction) {
+ TiObject* o = new (exec) TiCallbackFunction(exec, callAsFunction, propertyName);
+ thisObj->putDirect(propertyName, o, entry->attributes);
+ return o;
+ }
+ }
+ }
+ }
+
+ return throwError(exec, ReferenceError, "Static function property defined with NULL callAsFunction callback.");
+}
+
+template <class Base>
+TiValue TiCallbackObject<Base>::callbackGetter(TiExcState* exec, const Identifier& propertyName, const PropertySlot& slot)
+{
+ TiCallbackObject* thisObj = asCallbackObject(slot.slotBase());
+
+ TiObjectRef thisRef = toRef(thisObj);
+ RefPtr<OpaqueTiString> propertyNameRef;
+
+ for (TiClassRef jsClass = thisObj->classRef(); jsClass; jsClass = jsClass->parentClass)
+ if (TiObjectGetPropertyCallback getProperty = jsClass->getProperty) {
+ if (!propertyNameRef)
+ propertyNameRef = OpaqueTiString::create(propertyName.ustring());
+ TiValueRef exception = 0;
+ TiValueRef value;
+ {
+ TiLock::DropAllLocks dropAllLocks(exec);
+ value = getProperty(toRef(exec), thisRef, propertyNameRef.get(), &exception);
+ }
+ exec->setException(toJS(exec, exception));
+ if (value)
+ return toJS(exec, value);
+ if (exception)
+ return jsUndefined();
+ }
+
+ return throwError(exec, ReferenceError, "hasProperty callback returned true for a property that doesn't exist.");
+}
+
+} // namespace TI
251 TiCore/API/TiClassRef.cpp
@@ -0,0 +1,251 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 "TiClassRef.h"
+
+#include "APICast.h"
+#include "TiCallbackObject.h"
+#include "TiObjectRef.h"
+#include <runtime/InitializeThreading.h>
+#include <runtime/TiGlobalObject.h>
+#include <runtime/ObjectPrototype.h>
+#include <runtime/Identifier.h>
+
+using namespace TI;
+
+const TiClassDefinition kTiClassDefinitionEmpty = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
+OpaqueTiClass::OpaqueTiClass(const TiClassDefinition* definition, OpaqueTiClass* 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(UString::Rep::createFromUTF8(definition->className))
+ , m_staticValues(0)
+ , m_staticFunctions(0)
+{
+ initializeThreading();
+
+ if (const TiStaticValue* staticValue = definition->staticValues) {
+ m_staticValues = new OpaqueTiClassStaticValuesTable();
+ while (staticValue->name) {
+ m_staticValues->add(UString::Rep::createFromUTF8(staticValue->name),
+ new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes));
+ ++staticValue;
+ }
+ }
+
+ if (const TiStaticFunction* staticFunction = definition->staticFunctions) {
+ m_staticFunctions = new OpaqueTiClassStaticFunctionsTable();
+ while (staticFunction->name) {
+ m_staticFunctions->add(UString::Rep::createFromUTF8(staticFunction->name),
+ new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes));
+ ++staticFunction;
+ }
+ }
+
+ if (protoClass)
+ prototypeClass = TiClassRetain(protoClass);
+}
+
+OpaqueTiClass::~OpaqueTiClass()
+{
+ ASSERT(!m_className.rep()->identifierTable());
+
+ if (m_staticValues) {
+ OpaqueTiClassStaticValuesTable::const_iterator end = m_staticValues->end();
+ for (OpaqueTiClassStaticValuesTable::const_iterator it = m_staticValues->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ delete it->second;
+ }
+ delete m_staticValues;
+ }
+
+ if (m_staticFunctions) {
+ OpaqueTiClassStaticFunctionsTable::const_iterator end = m_staticFunctions->end();
+ for (OpaqueTiClassStaticFunctionsTable::const_iterator it = m_staticFunctions->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ delete it->second;
+ }
+ delete m_staticFunctions;
+ }
+
+ if (prototypeClass)
+ TiClassRelease(prototypeClass);
+}
+
+PassRefPtr<OpaqueTiClass> OpaqueTiClass::createNoAutomaticPrototype(const TiClassDefinition* definition)
+{
+ return adoptRef(new OpaqueTiClass(definition, 0));
+}
+
+static void clearReferenceToPrototype(TiObjectRef prototype)
+{
+ OpaqueTiClassContextData* jsClassData = static_cast<OpaqueTiClassContextData*>(TiObjectGetPrivate(prototype));
+ ASSERT(jsClassData);
+ jsClassData->cachedPrototype = 0;
+}
+
+PassRefPtr<OpaqueTiClass> OpaqueTiClass::create(const TiClassDefinition* definition)
+{
+ if (const TiStaticFunction* staticFunctions = definition->staticFunctions) {
+ // copy functions into a prototype class
+ TiClassDefinition protoDefinition = kTiClassDefinitionEmpty;
+ protoDefinition.staticFunctions = staticFunctions;
+ protoDefinition.finalize = clearReferenceToPrototype;
+
+ // We are supposed to use TiClassRetain/Release but since we know that we currently have
+ // the only reference to this class object we cheat and use a RefPtr instead.
+ RefPtr<OpaqueTiClass> protoClass = adoptRef(new OpaqueTiClass(&protoDefinition, 0));
+
+ // remove functions from the original class
+ TiClassDefinition objectDefinition = *definition;
+ objectDefinition.staticFunctions = 0;
+
+ return adoptRef(new OpaqueTiClass(&objectDefinition, protoClass.get()));
+ }
+
+ return adoptRef(new OpaqueTiClass(definition, 0));
+}
+
+OpaqueTiClassContextData::OpaqueTiClassContextData(OpaqueTiClass* jsClass)
+ : m_class(jsClass)
+ , cachedPrototype(0)
+{
+ if (jsClass->m_staticValues) {
+ staticValues = new OpaqueTiClassStaticValuesTable;
+ OpaqueTiClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end();
+ for (OpaqueTiClassStaticValuesTable::const_iterator it = jsClass->m_staticValues->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ staticValues->add(UString::Rep::createCopying(it->first->data(), it->first->size()),
+ new StaticValueEntry(it->second->getProperty, it->second->setProperty, it->second->attributes));
+ }
+
+ } else
+ staticValues = 0;
+
+
+ if (jsClass->m_staticFunctions) {
+ staticFunctions = new OpaqueTiClassStaticFunctionsTable;
+ OpaqueTiClassStaticFunctionsTable::const_iterator end = jsClass->m_staticFunctions->end();
+ for (OpaqueTiClassStaticFunctionsTable::const_iterator it = jsClass->m_staticFunctions->begin(); it != end; ++it) {
+ ASSERT(!it->first->identifierTable());
+ staticFunctions->add(UString::Rep::createCopying(it->first->data(), it->first->size()),
+ new StaticFunctionEntry(it->second->callAsFunction, it->second->attributes));
+ }
+
+ } else
+ staticFunctions = 0;
+}
+
+OpaqueTiClassContextData::~OpaqueTiClassContextData()
+{
+ if (staticValues) {
+ deleteAllValues(*staticValues);
+ delete staticValues;
+ }
+
+ if (staticFunctions) {
+ deleteAllValues(*staticFunctions);
+ delete staticFunctions;
+ }
+}
+
+OpaqueTiClassContextData& OpaqueTiClass::contextData(TiExcState* exec)
+{
+ OpaqueTiClassContextData*& contextData = exec->globalData().opaqueTiClassData.add(this, 0).first->second;
+ if (!contextData)
+ contextData = new OpaqueTiClassContextData(this);
+ return *contextData;
+}
+
+UString OpaqueTiClass::className()
+{
+ // Make a deep copy, so that the caller has no chance to put the original into IdentifierTable.
+ return UString(m_className.data(), m_className.size());
+}
+
+OpaqueTiClassStaticValuesTable* OpaqueTiClass::staticValues(TI::TiExcState* exec)
+{
+ OpaqueTiClassContextData& jsClassData = contextData(exec);
+ return jsClassData.staticValues;
+}
+
+OpaqueTiClassStaticFunctionsTable* OpaqueTiClass::staticFunctions(TI::TiExcState* exec)
+{
+ OpaqueTiClassContextData& 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 TiClass whose prototype you want to get.
+ @result The TiObject 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.
+*/
+TiObject* OpaqueTiClass::prototype(TiExcState* exec)
+{
+ /* Class (C++) and prototype (JS) inheritance are parallel, so:
+ * (C++) | (JS)
+ * ParentClass | ParentClassPrototype
+ * ^ | ^
+ * | | |
+ * DerivedClass | DerivedClassPrototype
+ */
+
+ if (!prototypeClass)
+ return 0;
+
+ OpaqueTiClassContextData& jsClassData = contextData(exec);
+
+ if (!jsClassData.cachedPrototype) {
+ // Recursive, but should be good enough for our purposes
+ jsClassData.cachedPrototype = new (exec) TiCallbackObject<TiObject>(exec, exec->lexicalGlobalObject()->callbackObjectStructure(), prototypeClass, &jsClassData); // set jsClassData as the object's private data, so it can clear our reference on destruction
+ if (parentClass) {
+ if (TiObject* prototype = parentClass->prototype(exec))
+ jsClassData.cachedPrototype->setPrototype(prototype);
+ }
+ }
+ return jsClassData.cachedPrototype;
+}
129 TiCore/API/TiClassRef.h
@@ -0,0 +1,129 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 TiClassRef_h
+#define TiClassRef_h
+
+#include "TiObjectRef.h"
+
+#include <runtime/TiObject.h>
+#include <runtime/Protect.h>
+#include <runtime/UString.h>
+#include <wtf/HashMap.h>
+#include <wtf/RefCounted.h>
+
+struct StaticValueEntry : FastAllocBase {
+ StaticValueEntry(TiObjectGetPropertyCallback _getProperty, TiObjectSetPropertyCallback _setProperty, TiPropertyAttributes _attributes)
+ : getProperty(_getProperty), setProperty(_setProperty), attributes(_attributes)
+ {
+ }
+
+ TiObjectGetPropertyCallback getProperty;
+ TiObjectSetPropertyCallback setProperty;
+ TiPropertyAttributes attributes;
+};
+
+struct StaticFunctionEntry : FastAllocBase {
+ StaticFunctionEntry(TiObjectCallAsFunctionCallback _callAsFunction, TiPropertyAttributes _attributes)
+ : callAsFunction(_callAsFunction), attributes(_attributes)
+ {
+ }
+
+ TiObjectCallAsFunctionCallback callAsFunction;
+ TiPropertyAttributes attributes;
+};
+
+typedef HashMap<RefPtr<TI::UString::Rep>, StaticValueEntry*> OpaqueTiClassStaticValuesTable;
+typedef HashMap<RefPtr<TI::UString::Rep>, StaticFunctionEntry*> OpaqueTiClassStaticFunctionsTable;
+
+struct OpaqueTiClass;
+
+// An OpaqueTiClass (TiClass) 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 OpaqueTiClassContextData : Noncopyable {
+ OpaqueTiClassContextData(OpaqueTiClass*);
+ ~OpaqueTiClassContextData();
+
+ // It is necessary to keep OpaqueTiClass alive because of the following rare scenario:
+ // 1. A class is created and used, so its context data is stored in TiGlobalData hash map.
+ // 2. The class is released, and when all JS objects that use it are collected, OpaqueTiClass
+ // 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 TiGlobalData and used.
+ RefPtr<OpaqueTiClass> m_class;
+
+ OpaqueTiClassStaticValuesTable* staticValues;
+ OpaqueTiClassStaticFunctionsTable* staticFunctions;
+ TI::TiObject* cachedPrototype;
+};
+
+struct OpaqueTiClass : public ThreadSafeShared<OpaqueTiClass> {
+ static PassRefPtr<OpaqueTiClass> create(const TiClassDefinition*);
+ static PassRefPtr<OpaqueTiClass> createNoAutomaticPrototype(const TiClassDefinition*);
+ ~OpaqueTiClass();
+
+ TI::UString className();
+ OpaqueTiClassStaticValuesTable* staticValues(TI::TiExcState*);
+ OpaqueTiClassStaticFunctionsTable* staticFunctions(TI::TiExcState*);
+ TI::TiObject* prototype(TI::TiExcState*);
+
+ OpaqueTiClass* parentClass;
+ OpaqueTiClass* prototypeClass;
+
+ TiObjectInitializeCallback initialize;
+ TiObjectFinalizeCallback finalize;
+ TiObjectHasPropertyCallback hasProperty;
+ TiObjectGetPropertyCallback getProperty;
+ TiObjectSetPropertyCallback setProperty;
+ TiObjectDeletePropertyCallback deleteProperty;
+ TiObjectGetPropertyNamesCallback getPropertyNames;
+ TiObjectCallAsFunctionCallback callAsFunction;
+ TiObjectCallAsConstructorCallback callAsConstructor;
+ TiObjectHasInstanceCallback hasInstance;
+ TiObjectConvertToTypeCallback convertToType;
+
+private:
+ friend struct OpaqueTiClassContextData;
+
+ OpaqueTiClass();
+ OpaqueTiClass(const OpaqueTiClass&);
+ OpaqueTiClass(const TiClassDefinition*, OpaqueTiClass* protoClass);
+
+ OpaqueTiClassContextData& contextData(TI::TiExcState*);
+
+ // UStrings in these data members should not be put into any IdentifierTable.
+ TI::UString m_className;
+ OpaqueTiClassStaticValuesTable* m_staticValues;
+ OpaqueTiClassStaticFunctionsTable* m_staticFunctions;
+};
+
+#endif // TiClassRef_h
171 TiCore/API/TiContextRef.cpp
@@ -0,0 +1,171 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 "TiContextRef.h"
+#include "TiContextRefPrivate.h"
+
+#include "APICast.h"
+#include "InitializeThreading.h"
+#include "TiCallbackObject.h"
+#include "TiClassRef.h"
+#include "TiGlobalObject.h"
+#include "TiObject.h"
+#include <wtf/Platform.h>
+
+#if PLATFORM(DARWIN)
+#include <mach-o/dyld.h>
+
+static const int32_t webkitFirstVersionWithConcurrentGlobalContexts = 0x2100500; // 528.5.0
+#endif
+
+using namespace TI;
+
+TiContextGroupRef TiContextGroupCreate()
+{
+ initializeThreading();
+ return toRef(TiGlobalData::create().releaseRef());
+}
+
+TiContextGroupRef TiContextGroupRetain(TiContextGroupRef group)
+{
+ toJS(group)->ref();
+ return group;
+}
+
+void TiContextGroupRelease(TiContextGroupRef group)
+{
+ toJS(group)->deref();
+}
+
+TiGlobalContextRef TiGlobalContextCreate(TiClassRef globalObjectClass)
+{
+ initializeThreading();
+#if PLATFORM(DARWIN)
+ // When running on Tiger or Leopard, or if the application was linked before TiGlobalContextCreate was changed
+ // to use a unique TiGlobalData, we use a shared one for compatibility.
+#if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD)
+ if (NSVersionOfLinkTimeLibrary("TiCore") <= webkitFirstVersionWithConcurrentGlobalContexts) {
+#else
+ {
+#endif
+ TiLock lock(LockForReal);
+ return TiGlobalContextCreateInGroup(toRef(&TiGlobalData::sharedInstance()), globalObjectClass);
+ }
+#endif // PLATFORM(DARWIN)
+
+ return TiGlobalContextCreateInGroup(0, globalObjectClass);
+}
+
+TiGlobalContextRef TiGlobalContextCreateInGroup(TiContextGroupRef group, TiClassRef globalObjectClass)
+{
+ initializeThreading();
+
+ TiLock lock(LockForReal);
+
+ RefPtr<TiGlobalData> globalData = group ? PassRefPtr<TiGlobalData>(toJS(group)) : TiGlobalData::create();
+
+#if ENABLE(JSC_MULTIPLE_THREADS)
+ globalData->makeUsableFromMultipleThreads();
+#endif
+
+ if (!globalObjectClass) {
+ TiGlobalObject* globalObject = new (globalData.get()) TiGlobalObject;
+ return TiGlobalContextRetain(toGlobalRef(globalObject->globalExec()));
+ }
+
+ TiGlobalObject* globalObject = new (globalData.get()) TiCallbackObject<TiGlobalObject>(globalObjectClass);
+ TiExcState* exec = globalObject->globalExec();
+ TiValue prototype = globalObjectClass->prototype(exec);
+ if (!prototype)
+ prototype = jsNull();
+ globalObject->resetPrototype(prototype);
+ return TiGlobalContextRetain(toGlobalRef(exec));
+}
+
+TiGlobalContextRef TiGlobalContextRetain(TiGlobalContextRef ctx)
+{
+ TiExcState* exec = toJS(ctx);
+ TiLock lock(exec);
+
+ TiGlobalData& globalData = exec->globalData();
+
+ globalData.heap.registerThread();
+
+ gcProtect(exec->dynamicGlobalObject());
+ globalData.ref();
+ return ctx;
+}
+
+void TiGlobalContextRelease(TiGlobalContextRef ctx)
+{
+ TiExcState* exec = toJS(ctx);
+ TiLock lock(exec);
+
+ gcUnprotect(exec->dynamicGlobalObject());
+
+ TiGlobalData& globalData = exec->globalData();
+ if (globalData.refCount() == 2) { // One reference is held by TiGlobalObject, another added by TiGlobalContextRetain().
+ // The last reference was released, this is our last chance to collect.
+ ASSERT(!globalData.heap.protectedObjectCount());
+ ASSERT(!globalData.heap.isBusy());
+ globalData.heap.destroy();
+ } else
+ globalData.heap.collect();
+
+ globalData.deref();
+}
+
+TiObjectRef TiContextGetGlobalObject(TiContextRef ctx)
+{
+ TiExcState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ TiLock lock(exec);
+
+ // It is necessary to call toThisObject to get the wrapper object when used with WebCore.
+ return toRef(exec->lexicalGlobalObject()->toThisObject(exec));
+}
+
+TiContextGroupRef TiContextGetGroup(TiContextRef ctx)
+{
+ TiExcState* exec = toJS(ctx);
+ return toRef(&exec->globalData());
+}
+
+TiGlobalContextRef TiContextGetGlobalContext(TiContextRef ctx)
+{
+ TiExcState* exec = toJS(ctx);
+ exec->globalData().heap.registerThread();
+ TiLock lock(exec);
+
+ return toGlobalRef(exec->lexicalGlobalObject()->globalExec());
+}
139 TiCore/API/TiContextRef.h
@@ -0,0 +1,139 @@
+/**
+ * Appcelerator Titanium License
+ * This source code and all modifications done by Appcelerator
+ * are licensed under the Apache Public License (version 2) and
+ * are Copyright (c) 2009 by Appcelerator, Inc.
+ */
+
+/*
+ * 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 TiContextRef_h
+#define TiContextRef_h
+
+#include <TiCore/TiObjectRef.h>
+#include <TiCore/TiValueRef.h>
+#include <TiCore/WebKitAvailability.h>
+
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*!
+@function
+@abstract Creates a Ti context group.
+@discussion A TiContextGroup associates Ti contexts with one another.
+ Contexts in the same group may share and exchange Ti objects. Sharing and/or exchanging
+ Ti 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 TiContextGroup.
+*/
+JS_EXPORT TiContextGroupRef TiContextGroupCreate() AVAILABLE_IN_WEBKIT_VERSION_4_0;
+
+/*!
+@function
+@abstract Retains a Ti context group.
+@param group The TiContextGroup to retain.
+@result A TiContextGroup that is the same as group.
+*/
+JS_EXPORT TiContextGroupRef TiContextGroupRetain(TiContextGroupRef group) AVAILABLE_IN_WEBKIT_VERSION_4_0;
+
+/*!
+@function
+@abstract Releases a Ti context group.
+@param group The TiContextGroup to release.
+*/
+JS_EXPORT void TiContextGroupRelease(TiContextGroupRef group) AVAILABLE_IN_WEBKIT_VERSION_4_0;
+
+/*!
+@function
+@abstract Creates a global Ti execution context.
+@discussion TiGlobalContextCreate allocates a global object and populates it with all the
+ built-in Ti 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 TiGlobalContext with a global object of class globalObjectClass.
+*/
+JS_EXPORT TiGlobalContextRef TiGlobalContextCreate(TiClassRef globalObjectClass) AVAILABLE_WEBKIT_VERSION_3_0_AND_LATER;
+
+/*!
+@function
+@abstract Creates a global Ti execution context in the context group provided.
+@discussion TiGlobalContextCreateInGroup allocates a global object and populates it with
+ all the built-in Ti 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 TiGlobalContext with a global object of class globalObjectClass and a context
+ group equal to group.
+*/
+JS_EXPORT TiGlobalContextRef TiGlobalContextCreateInGroup(TiContextGroupRef group, TiClassRef globalObjectClass) AVAILABLE_IN_WEBKIT_VERSION_4_0;
+
+/*!
+@function
+@abstract Retains a global Ti execution context.
+@param ctx The TiGlobalContext to retain.
+@result A TiGlobalContext that is the same as ctx.
+*/
+JS_EXPORT TiGlobalContextRef TiGlobalContextRetain(TiGlobalContextRef ctx);
+
+/*!
+@function
+@abstract Releases a global Ti execution context.
+@param ctx The TiGlobalContext to release.
+*/
+JS_EXPORT void TiGlobalContextRelease(TiGlobalContextRef ctx);
+
+/*!
+@function