| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 This file is part of the WebKit open source project. | |
| 3 This file has been generated by generate-bindings.pl. DO NOT MODIFY! | |
| 4 | |
| 5 This library is free software; you can redistribute it and/or | |
| 6 modify it under the terms of the GNU Library General Public | |
| 7 License as published by the Free Software Foundation; either | |
| 8 version 2 of the License, or (at your option) any later version. | |
| 9 | |
| 10 This library is distributed in the hope that it will be useful, | |
| 11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 Library General Public License for more details. | |
| 14 | |
| 15 You should have received a copy of the GNU Library General Public License | |
| 16 along with this library; see the file COPYING.LIB. If not, write to | |
| 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 18 Boston, MA 02111-1307, USA. | |
| 19 */ | |
| 20 | |
| 21 #include "config.h" | |
| 22 #include "V8TestNamedConstructor.h" | |
| 23 | |
| 24 #include "BindingState.h" | |
| 25 #include "ContextFeatures.h" | |
| 26 #include "ExceptionCode.h" | |
| 27 #include "Frame.h" | |
| 28 #include "RuntimeEnabledFeatures.h" | |
| 29 #include "V8Binding.h" | |
| 30 #include "V8DOMWrapper.h" | |
| 31 #include "V8Document.h" | |
| 32 #include <wtf/UnusedParam.h> | |
| 33 | |
| 34 #if ENABLE(BINDING_INTEGRITY) | |
| 35 #if defined(OS_WIN) | |
| 36 #pragma warning(disable: 4483) | |
| 37 extern "C" { extern void (*const __identifier("??_7TestNamedConstructor@WebCore@
@6B@")[])(); } | |
| 38 #else | |
| 39 extern "C" { extern void* _ZTVN7WebCore20TestNamedConstructorE[]; } | |
| 40 #endif | |
| 41 #endif // ENABLE(BINDING_INTEGRITY) | |
| 42 | |
| 43 namespace WebCore { | |
| 44 | |
| 45 #if ENABLE(BINDING_INTEGRITY) | |
| 46 // This checks if a DOM object that is about to be wrapped is valid. | |
| 47 // Specifically, it checks that a vtable of the DOM object is equal to | |
| 48 // a vtable of an expected class. | |
| 49 // Due to a dangling pointer, the DOM object you are wrapping might be | |
| 50 // already freed or realloced. If freed, the check will fail because | |
| 51 // a free list pointer should be stored at the head of the DOM object. | |
| 52 // If realloced, the check will fail because the vtable of the DOM object | |
| 53 // differs from the expected vtable (unless the same class of DOM object | |
| 54 // is realloced on the slot). | |
| 55 inline void checkTypeOrDieTrying(TestNamedConstructor* object) | |
| 56 { | |
| 57 void* actualVTablePointer = *(reinterpret_cast<void**>(object)); | |
| 58 #if defined(OS_WIN) | |
| 59 void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7Test
NamedConstructor@WebCore@@6B@")); | |
| 60 #else | |
| 61 void* expectedVTablePointer = &_ZTVN7WebCore20TestNamedConstructorE[2]; | |
| 62 #endif | |
| 63 if (actualVTablePointer != expectedVTablePointer) | |
| 64 CRASH(); | |
| 65 } | |
| 66 #endif // ENABLE(BINDING_INTEGRITY) | |
| 67 | |
| 68 WrapperTypeInfo V8TestNamedConstructor::info = { V8TestNamedConstructor::GetTemp
late, V8TestNamedConstructor::derefObject, V8TestNamedConstructor::toActiveDOMOb
ject, 0, 0, V8TestNamedConstructor::installPerContextPrototypeProperties, 0, Wra
pperTypeObjectPrototype }; | |
| 69 | |
| 70 namespace TestNamedConstructorV8Internal { | |
| 71 | |
| 72 template <typename T> void V8_USE(T) { } | |
| 73 | |
| 74 } // namespace TestNamedConstructorV8Internal | |
| 75 | |
| 76 WrapperTypeInfo V8TestNamedConstructorConstructor::info = { V8TestNamedConstruct
orConstructor::GetTemplate, V8TestNamedConstructor::derefObject, V8TestNamedCons
tructor::toActiveDOMObject, 0, 0, V8TestNamedConstructor::installPerContextProto
typeProperties, 0, WrapperTypeObjectPrototype }; | |
| 77 | |
| 78 static v8::Handle<v8::Value> V8TestNamedConstructorConstructorCallback(const v8:
:Arguments& args) | |
| 79 { | |
| 80 | |
| 81 if (!args.IsConstructCall()) | |
| 82 return throwTypeError("DOM object constructor cannot be called as a func
tion.", args.GetIsolate()); | |
| 83 | |
| 84 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) | |
| 85 return args.Holder(); | |
| 86 | |
| 87 Document* document = currentDocument(BindingState::instance()); | |
| 88 | |
| 89 // Make sure the document is added to the DOM Node map. Otherwise, the TestN
amedConstructor instance | |
| 90 // may end up being the only node in the map and get garbage-collected prema
turely. | |
| 91 toV8(document, args.Holder(), args.GetIsolate()); | |
| 92 | |
| 93 if (args.Length() < 1) | |
| 94 return throwNotEnoughArgumentsError(args.GetIsolate()); | |
| 95 | |
| 96 ExceptionCode ec = 0; | |
| 97 V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str1, args[0]); | |
| 98 V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str2, args[1]); | |
| 99 V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str3, argumentOrNull(arg
s, 2)); | |
| 100 | |
| 101 RefPtr<TestNamedConstructor> impl = TestNamedConstructor::createForJSConstru
ctor(document, str1, str2, str3, ec); | |
| 102 v8::Handle<v8::Object> wrapper = args.Holder(); | |
| 103 if (ec) | |
| 104 goto fail; | |
| 105 | |
| 106 V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestNamedConstru
ctorConstructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Depende
nt); | |
| 107 return wrapper; | |
| 108 fail: | |
| 109 return setDOMException(ec, args.GetIsolate()); | |
| 110 } | |
| 111 | |
| 112 v8::Persistent<v8::FunctionTemplate> V8TestNamedConstructorConstructor::GetTempl
ate(v8::Isolate* isolate, WrapperWorldType currentWorldType) | |
| 113 { | |
| 114 static v8::Persistent<v8::FunctionTemplate> cachedTemplate; | |
| 115 if (!cachedTemplate.IsEmpty()) | |
| 116 return cachedTemplate; | |
| 117 | |
| 118 v8::HandleScope scope; | |
| 119 v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(V8TestNam
edConstructorConstructorCallback); | |
| 120 | |
| 121 v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate(); | |
| 122 instance->SetInternalFieldCount(V8TestNamedConstructor::internalFieldCount); | |
| 123 result->SetClassName(v8::String::NewSymbol("TestNamedConstructor")); | |
| 124 result->Inherit(V8TestNamedConstructor::GetTemplate(isolate, currentWorldTyp
e)); | |
| 125 | |
| 126 cachedTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, result); | |
| 127 return cachedTemplate; | |
| 128 } | |
| 129 | |
| 130 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestNamedConstructorTempl
ate(v8::Persistent<v8::FunctionTemplate> desc, v8::Isolate* isolate, WrapperWorl
dType currentWorldType) | |
| 131 { | |
| 132 desc->ReadOnlyPrototype(); | |
| 133 | |
| 134 v8::Local<v8::Signature> defaultSignature; | |
| 135 defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestNamedCon
structor", v8::Persistent<v8::FunctionTemplate>(), V8TestNamedConstructor::inter
nalFieldCount, | |
| 136 0, 0, | |
| 137 0, 0, isolate, currentWorldType); | |
| 138 UNUSED_PARAM(defaultSignature); // In some cases, it will not be used. | |
| 139 | |
| 140 | |
| 141 // Custom toString template | |
| 142 desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->to
StringTemplate()); | |
| 143 return desc; | |
| 144 } | |
| 145 | |
| 146 v8::Persistent<v8::FunctionTemplate> V8TestNamedConstructor::GetTemplate(v8::Iso
late* isolate, WrapperWorldType currentWorldType) | |
| 147 { | |
| 148 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | |
| 149 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWo
rldType).find(&info); | |
| 150 if (result != data->templateMap(currentWorldType).end()) | |
| 151 return result->value; | |
| 152 | |
| 153 v8::HandleScope handleScope; | |
| 154 v8::Persistent<v8::FunctionTemplate> templ = | |
| 155 ConfigureV8TestNamedConstructorTemplate(data->rawTemplate(&info, current
WorldType), isolate, currentWorldType); | |
| 156 data->templateMap(currentWorldType).add(&info, templ); | |
| 157 return templ; | |
| 158 } | |
| 159 | |
| 160 bool V8TestNamedConstructor::HasInstance(v8::Handle<v8::Value> value, v8::Isolat
e* isolate, WrapperWorldType currentWorldType) | |
| 161 { | |
| 162 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWor
ldType); | |
| 163 } | |
| 164 | |
| 165 bool V8TestNamedConstructor::HasInstanceInAnyWorld(v8::Handle<v8::Value> value,
v8::Isolate* isolate) | |
| 166 { | |
| 167 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld) | |
| 168 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWo
rld) | |
| 169 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorl
d); | |
| 170 } | |
| 171 | |
| 172 ActiveDOMObject* V8TestNamedConstructor::toActiveDOMObject(v8::Handle<v8::Object
> object) | |
| 173 { | |
| 174 return toNative(object); | |
| 175 } | |
| 176 | |
| 177 | |
| 178 v8::Handle<v8::Object> V8TestNamedConstructor::createWrapper(PassRefPtr<TestName
dConstructor> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate
) | |
| 179 { | |
| 180 ASSERT(impl.get()); | |
| 181 ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty()); | |
| 182 | |
| 183 #if ENABLE(BINDING_INTEGRITY) | |
| 184 checkTypeOrDieTrying(impl.get()); | |
| 185 #endif | |
| 186 | |
| 187 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext
, &info, impl.get(), isolate); | |
| 188 if (UNLIKELY(wrapper.IsEmpty())) | |
| 189 return wrapper; | |
| 190 | |
| 191 installPerContextProperties(wrapper, impl.get(), isolate); | |
| 192 V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasD
ependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Indep
endent); | |
| 193 return wrapper; | |
| 194 } | |
| 195 void V8TestNamedConstructor::derefObject(void* object) | |
| 196 { | |
| 197 static_cast<TestNamedConstructor*>(object)->deref(); | |
| 198 } | |
| 199 | |
| 200 } // namespace WebCore | |
| OLD | NEW |