| 1 | /* |
| 2 | * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/config.h`/ |
| 27 | #include "JSClassRef.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/API/JSClassRef.h`/ |
| 28 | |
| 29 | #include "APICast.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/API/APICast.h`/ |
| 30 | #include "JSCallbackObject.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/API/JSCallbackObject.h`/ |
| 31 | #include "JSObjectRef.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/API/JSObjectRef.h`/ |
| 32 | #include <runtime/InitializeThreading.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/InitializeThreading.h`/ |
| 33 | #include <runtime/JSGlobalObject.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSGlobalObject.h`/ |
| 34 | #include <runtime/ObjectPrototype.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/ObjectPrototype.h`/ |
| 35 | #include <runtime/Identifier.h>cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/runtime/Identifier.h`/ |
| 36 | |
| 37 | using namespace std; |
| 38 | using namespace JSCcxx . . $ `<built-in>:463:9`!; |
| 39 | |
| 40 | const JSClassDefinition kJSClassDefinitionEmptycxx . . $ kJSClassDefinitionEmpty. = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
| 41 | |
| 42 | OpaqueJSClasscxx . . $ OpaqueJSClass#::OpaqueJSClasscxx . . $ OpaqueJSClass#OpaqueJSClass(f031348405501082).(const JSClassDefinition* definition, OpaqueJSClasscxx . . $ OpaqueJSClass#* protoClass) |
| 43 | : parentClasscxx . . $ OpaqueJSClass#parentClass.(definition->parentClass) |
| 44 | , prototypeClasscxx . . $ OpaqueJSClass#prototypeClass.(0) |
| 45 | , initializecxx . . $ OpaqueJSClass#initialize.(definition->initialize) |
| 46 | , finalizecxx . . $ OpaqueJSClass#finalize.(definition->finalize) |
| 47 | , hasPropertycxx . . $ OpaqueJSClass#hasProperty.(definition->hasProperty) |
| 48 | , getPropertycxx . . $ OpaqueJSClass#getProperty.(definition->getProperty) |
| 49 | , setPropertycxx . . $ OpaqueJSClass#setProperty.(definition->setProperty) |
| 50 | , deletePropertycxx . . $ OpaqueJSClass#deleteProperty.(definition->deleteProperty) |
| 51 | , getPropertyNamescxx . . $ OpaqueJSClass#getPropertyNames.(definition->getPropertyNames) |
| 52 | , callAsFunctioncxx . . $ OpaqueJSClass#callAsFunction.(definition->callAsFunction) |
| 53 | , callAsConstructorcxx . . $ OpaqueJSClass#callAsConstructor.(definition->callAsConstructor) |
| 54 | , hasInstancecxx . . $ OpaqueJSClass#hasInstance.(definition->hasInstance) |
| 55 | , convertToTypecxx . . $ OpaqueJSClass#convertToType.(definition->convertToType) |
| 56 | , m_className(UString::createFromUTF8(definition->className).rep()->ref()) |
| 57 | , m_staticValuescxx . . $ OpaqueJSClass#m_staticValues.(0) |
| 58 | , m_staticFunctionscxx . . $ OpaqueJSClass#m_staticFunctions.(0) |
| 59 | { |
| 60 | initializeThreadingcxx . . $ QTJSC/initializeThreading(49f6e7a06ebc5aa8).(); |
| 61 | |
| 62 | if (const JSStaticValue* staticValue = definition->staticValues) { |
| 63 | m_staticValuescxx . . $ OpaqueJSClass#m_staticValues. = new OpaqueJSClassStaticValuesTablecxx . . $ OpaqueJSClassStaticValuesTable#(); |
| 64 | while (staticValue->name) { |
| 65 | // Use a local variable here to sidestep an RVCT compiler bug. |
| 66 | StaticValueEntrycxx . . $ StaticValueEntry#* entry = new StaticValueEntrycxx . . $ StaticValueEntry#(staticValue->getProperty, staticValue->setProperty, staticValue->attributes); |
| 67 | m_staticValuescxx . . $ OpaqueJSClass#m_staticValues.->add(UStringcxx . . $ QTJSC/UString#::createFromUTF8cxx . . $ QTJSC/UString#createFromUTF8(7997a73d481bd958).(staticValue->name).repcxx . . $ QTJSC/UString#rep(eff8ac5d0836371c).()->refcxx . . $ QTJSC/UStringImpl#ref(b56a90d0afa3b8ee).(), entry); |
| 68 | ++staticValue; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if (const JSStaticFunction* staticFunction = definition->staticFunctions) { |
| 73 | m_staticFunctionscxx . . $ OpaqueJSClass#m_staticFunctions. = new OpaqueJSClassStaticFunctionsTablecxx . . $ OpaqueJSClassStaticFunctionsTable#(); |
| 74 | while (staticFunction->name) { |
| 75 | // Use a local variable here to sidestep an RVCT compiler bug. |
| 76 | StaticFunctionEntrycxx . . $ StaticFunctionEntry#* entry = new StaticFunctionEntrycxx . . $ StaticFunctionEntry#(staticFunction->callAsFunction, staticFunction->attributes); |
| 77 | m_staticFunctionscxx . . $ OpaqueJSClass#m_staticFunctions.->add(UStringcxx . . $ QTJSC/UString#::createFromUTF8cxx . . $ QTJSC/UString#createFromUTF8(7997a73d481bd958).(staticFunction->name).repcxx . . $ QTJSC/UString#rep(eff8ac5d0836371c).()->refcxx . . $ QTJSC/UStringImpl#ref(b56a90d0afa3b8ee).(), entry); |
| 78 | ++staticFunction; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | if (protoClass) |
| 83 | prototypeClasscxx . . $ OpaqueJSClass#prototypeClass. = JSClassRetain(protoClass); |
| 84 | } |
| 85 | |
| 86 | OpaqueJSClasscxx . . $ OpaqueJSClass#::~cxx . . $ OpaqueJSClass#`~OpaqueJSClass`(49f6e7a06ebc5aa8).OpaqueJSClasscxx . . $ OpaqueJSClass#() |
| 87 | { |
| 88 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!m_className.rep()->isIdentifier()); |
| 89 | |
| 90 | if (m_staticValuescxx . . $ OpaqueJSClass#m_staticValues.) { |
| 91 | OpaqueJSClassStaticValuesTable::const_iterator end = m_staticValues->end(); |
| 92 | for (OpaqueJSClassStaticValuesTable::const_iterator it = m_staticValuescxx . . $ OpaqueJSClass#m_staticValues.->begin(); it !=cxx . . $ `operator!=`(8f8a8e6a6f1fc74b). endcxx . . $ std/end(309ad712043406cf).; ++it) { |
| 93 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!it->first->isIdentifier()); |
| 94 | delete it->second; |
| 95 | } |
| 96 | delete m_staticValuescxx . . $ OpaqueJSClass#m_staticValues.; |
| 97 | } |
| 98 | |
| 99 | if (m_staticFunctionscxx . . $ OpaqueJSClass#m_staticFunctions.) { |
| 100 | OpaqueJSClassStaticFunctionsTable::const_iterator end = m_staticFunctions->end(); |
| 101 | for (OpaqueJSClassStaticFunctionsTable::const_iterator it = m_staticFunctionscxx . . $ OpaqueJSClass#m_staticFunctions.->begin(); it !=cxx . . $ `operator!=`(8f8a8e6a6f1fc74b). endcxx . . $ std/end(309ad712043406cf).; ++it) { |
| 102 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!it->first->isIdentifier()); |
| 103 | delete it->second; |
| 104 | } |
| 105 | delete m_staticFunctionscxx . . $ OpaqueJSClass#m_staticFunctions.; |
| 106 | } |
| 107 | |
| 108 | if (prototypeClasscxx . . $ OpaqueJSClass#prototypeClass.) |
| 109 | JSClassRelease(prototypeClasscxx . . $ OpaqueJSClass#prototypeClass.); |
| 110 | } |
| 111 | |
| 112 | PassRefPtrcxx . . $ PassRefPtr#<OpaqueJSClasscxx . . $ OpaqueJSClass#> OpaqueJSClasscxx . . $ OpaqueJSClass#::createNoAutomaticPrototypecxx . . $ OpaqueJSClass#createNoAutomaticPrototype(bd14c5ac80c68ccd).(const JSClassDefinition* definition) |
| 113 | { |
| 114 | return adoptRefcxx . . $ adoptRef(e761da608bb8c29c).(new OpaqueJSClasscxx . . $ OpaqueJSClass#OpaqueJSClass(f031348405501082).(definition, 0)); |
| 115 | } |
| 116 | |
| 117 | static void clearReferenceToPrototypecxx . . $ clearReferenceToPrototype(403ada5bab4d5e75).(JSObjectRefcxx . . $ JSObjectRef# prototype) |
| 118 | { |
| 119 | OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#* jsClassData = static_cast<OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#*>(JSObjectGetPrivate(prototype)); |
| 120 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(jsClassData); |
| 121 | jsClassData->cachedPrototype = 0; |
| 122 | } |
| 123 | |
| 124 | PassRefPtrcxx . . $ PassRefPtr#<OpaqueJSClasscxx . . $ OpaqueJSClass#> OpaqueJSClasscxx . . $ OpaqueJSClass#::createcxx . . $ OpaqueJSClass#create(bd14c5ac80c68ccd).(const JSClassDefinition* clientDefinition) |
| 125 | { |
| 126 | JSClassDefinition definition = *clientDefinition; // Avoid modifying client copy. |
| 127 | |
| 128 | JSClassDefinition protoDefinition = kJSClassDefinitionEmptycxx . . $ kJSClassDefinitionEmpty.; |
| 129 | protoDefinition.finalize = clearReferenceToPrototypecxx . . $ clearReferenceToPrototype(403ada5bab4d5e75).; |
| 130 | swapcxx . . $ swap(bb2efc359ba8e76b).(definition.staticFunctions, protoDefinition.staticFunctions); // Move static functions to the prototype. |
| 131 | |
| 132 | // We are supposed to use JSClassRetain/Release but since we know that we currently have |
| 133 | // the only reference to this class object we cheat and use a RefPtr instead. |
| 134 | RefPtrcxx . . $ RefPtr#<OpaqueJSClasscxx . . $ OpaqueJSClass#> protoClass = adoptRef(new OpaqueJSClass(&protoDefinition, 0)); |
| 135 | return adoptRefcxx . . $ adoptRef(e761da608bb8c29c).(new OpaqueJSClasscxx . . $ OpaqueJSClass#(&definition, protoClass.get())); |
| 136 | } |
| 137 | |
| 138 | OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#::OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#OpaqueJSClassContextData(159998762f31489b).(OpaqueJSClasscxx . . $ OpaqueJSClass#* jsClass) |
| 139 | : m_class(jsClass) |
| 140 | { |
| 141 | if (jsClass->m_staticValuescxx . . $ OpaqueJSClass#m_staticValues.) { |
| 142 | staticValuescxx . . $ OpaqueJSClassContextData#staticValues. = new OpaqueJSClassStaticValuesTablecxx . . $ OpaqueJSClassStaticValuesTable#; |
| 143 | OpaqueJSClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end(); |
| 144 | for (OpaqueJSClassStaticValuesTable::const_iterator it = jsClass->m_staticValuescxx . . $ OpaqueJSClass#m_staticValues.->begin(); it !=cxx . . $ `operator!=`(8f8a8e6a6f1fc74b). endcxx . . $ std/end(309ad712043406cf).; ++it) { |
| 145 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!it->first->isIdentifier()); |
| 146 | // Use a local variable here to sidestep an RVCT compiler bug. |
| 147 | StaticValueEntrycxx . . $ StaticValueEntry#* entry = new StaticValueEntrycxx . . $ StaticValueEntry#(it->second->getProperty, it->second->setProperty, it->second->attributes); |
| 148 | staticValuescxx . . $ OpaqueJSClassContextData#staticValues.->add(UString::Rep::create(it->first->data(), it->first->size()), entry); |
| 149 | |
| 150 | } |
| 151 | |
| 152 | } else |
| 153 | staticValuescxx . . $ OpaqueJSClassContextData#staticValues. = 0; |
| 154 | |
| 155 | |
| 156 | if (jsClass->m_staticFunctionscxx . . $ OpaqueJSClass#m_staticFunctions.) { |
| 157 | staticFunctionscxx . . $ OpaqueJSClassContextData#staticFunctions. = new OpaqueJSClassStaticFunctionsTablecxx . . $ OpaqueJSClassStaticFunctionsTable#; |
| 158 | OpaqueJSClassStaticFunctionsTable::const_iterator end = jsClass->m_staticFunctions->end(); |
| 159 | for (OpaqueJSClassStaticFunctionsTable::const_iterator it = jsClass->m_staticFunctionscxx . . $ OpaqueJSClass#m_staticFunctions.->begin(); it !=cxx . . $ `operator!=`(8f8a8e6a6f1fc74b). endcxx . . $ std/end(309ad712043406cf).; ++it) { |
| 160 | ASSERTcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Assertions.h:184:9`!(!it->first->isIdentifier()); |
| 161 | // Use a local variable here to sidestep an RVCT compiler bug. |
| 162 | StaticFunctionEntrycxx . . $ StaticFunctionEntry#* entry = new StaticFunctionEntrycxx . . $ StaticFunctionEntry#(it->second->callAsFunction, it->second->attributes); |
| 163 | staticFunctionscxx . . $ OpaqueJSClassContextData#staticFunctions.->add(UString::Rep::create(it->first->data(), it->first->size()), entry); |
| 164 | } |
| 165 | |
| 166 | } else |
| 167 | staticFunctionscxx . . $ OpaqueJSClassContextData#staticFunctions. = 0; |
| 168 | } |
| 169 | |
| 170 | OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#::~cxx . . $ OpaqueJSClassContextData#`~OpaqueJSClassContextData`(49f6e7a06ebc5aa8).OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#() |
| 171 | { |
| 172 | if (staticValuescxx . . $ OpaqueJSClassContextData#staticValues.) { |
| 173 | deleteAllValues(*staticValuescxx . . $ OpaqueJSClassContextData#staticValues.); |
| 174 | delete staticValuescxx . . $ OpaqueJSClassContextData#staticValues.; |
| 175 | } |
| 176 | |
| 177 | if (staticFunctionscxx . . $ OpaqueJSClassContextData#staticFunctions.) { |
| 178 | deleteAllValues(*staticFunctionscxx . . $ OpaqueJSClassContextData#staticFunctions.); |
| 179 | delete staticFunctionscxx . . $ OpaqueJSClassContextData#staticFunctions.; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#& OpaqueJSClasscxx . . $ OpaqueJSClass#::contextDatacxx . . $ OpaqueJSClass#contextData(f87e7ed45c1bfa41).(ExecStatecxx . . $ QTJSC/ExecState#* exec) |
| 184 | { |
| 185 | OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#*& contextData = exec->globalDatacxx . . $ QTJSC/ExecState#globalData(ae00a65ac2fd4a61).().opaqueJSClassData.add(this, 0).first->second; |
| 186 | if (!contextData) |
| 187 | contextData = new OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#OpaqueJSClassContextData(159998762f31489b).(this); |
| 188 | return *contextData; |
| 189 | } |
| 190 | |
| 191 | UStringcxx . . $ QTJSC/UString# OpaqueJSClasscxx . . $ OpaqueJSClass#::classNamecxx . . $ OpaqueJSClass#className(efe381e3afb22e2c).() |
| 192 | { |
| 193 | // Make a deep copy, so that the caller has no chance to put the original into IdentifierTable. |
| 194 | return UString(m_className.data(), m_className.size()); |
| 195 | } |
| 196 | |
| 197 | OpaqueJSClassStaticValuesTablecxx . . $ OpaqueJSClassStaticValuesTable#* OpaqueJSClasscxx . . $ OpaqueJSClass#::staticValuescxx . . $ OpaqueJSClass#staticValues(7d16391faedb28a0).(JSCcxx . . $ `<built-in>:463:9`!::ExecStatecxx . . $ QTJSC/ExecState#* exec) |
| 198 | { |
| 199 | OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#& jsClassData = contextDatacxx . . $ OpaqueJSClass#contextData(f87e7ed45c1bfa41).(exec); |
| 200 | return jsClassData.staticValuescxx . . $ OpaqueJSClassContextData#staticValues.; |
| 201 | } |
| 202 | |
| 203 | OpaqueJSClassStaticFunctionsTablecxx . . $ OpaqueJSClassStaticFunctionsTable#* OpaqueJSClasscxx . . $ OpaqueJSClass#::staticFunctionscxx . . $ OpaqueJSClass#staticFunctions(7d16391faedb28a0).(JSCcxx . . $ `<built-in>:463:9`!::ExecStatecxx . . $ QTJSC/ExecState#* exec) |
| 204 | { |
| 205 | OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#& jsClassData = contextDatacxx . . $ OpaqueJSClass#contextData(f87e7ed45c1bfa41).(exec); |
| 206 | return jsClassData.staticFunctionscxx . . $ OpaqueJSClassContextData#staticFunctions.; |
| 207 | } |
| 208 | |
| 209 | /*! |
| 210 | // Doc here in case we make this public. (Hopefully we won't.) |
| 211 | @function |
| 212 | @abstract Returns the prototype that will be used when constructing an object with a given class. |
| 213 | @param ctx The execution context to use. |
| 214 | @param jsClass A JSClass whose prototype you want to get. |
| 215 | @result The JSObject prototype that was automatically generated for jsClass, or NULL if no prototype was automatically generated. This is the prototype that will be used when constructing an object using jsClass. |
| 216 | */ |
| 217 | JSObjectcxx . . $ QTJSC/JSObject#* OpaqueJSClasscxx . . $ OpaqueJSClass#::prototypecxx . . $ OpaqueJSClass#prototype(dc025d143f56633c).(ExecStatecxx . . $ QTJSC/ExecState#* exec) |
| 218 | { |
| 219 | /* Class (C++) and prototype (JS) inheritance are parallel, so: |
| 220 | * (C++) | (JS) |
| 221 | * ParentClass | ParentClassPrototype |
| 222 | * ^ | ^ |
| 223 | * | | | |
| 224 | * DerivedClass | DerivedClassPrototype |
| 225 | */ |
| 226 | |
| 227 | if (!prototypeClasscxx . . $ OpaqueJSClass#prototypeClass.) |
| 228 | return 0; |
| 229 | |
| 230 | OpaqueJSClassContextDatacxx . . $ OpaqueJSClassContextData#& jsClassData = contextDatacxx . . $ OpaqueJSClass#contextData(f87e7ed45c1bfa41).(exec); |
| 231 | |
| 232 | if (!jsClassData.cachedPrototype) { |
| 233 | // Recursive, but should be good enough for our purposes |
| 234 | jsClassData.cachedPrototype = new (exec) JSCallbackObject<JSObject>(exec, exec->lexicalGlobalObject()->callbackObjectStructure(), prototypeClass, &jsClassData); // set jsClassData as the object's private data, so it can clear our reference on destruction |
| 235 | if (parentClasscxx . . $ OpaqueJSClass#parentClass.) { |
| 236 | if (JSObjectcxx . . $ QTJSC/JSObject#* prototype = parentClasscxx . . $ OpaqueJSClass#parentClass.->prototypecxx . . $ OpaqueJSClass#prototype(dc025d143f56633c).(exec)) |
| 237 | jsClassData.cachedPrototype->setPrototype(prototype); |
| 238 | } |
| 239 | } |
| 240 | return jsClassData.cachedPrototype.get(); |
| 241 | } |