| 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 "V8TestNode.h" | |
| 23 | |
| 24 #include "BindingState.h" | |
| 25 #include "ContextFeatures.h" | |
| 26 #include "Frame.h" | |
| 27 #include "RuntimeEnabledFeatures.h" | |
| 28 #include "V8Binding.h" | |
| 29 #include "V8DOMWrapper.h" | |
| 30 #include "V8Node.h" | |
| 31 #include <wtf/UnusedParam.h> | |
| 32 | |
| 33 #if ENABLE(BINDING_INTEGRITY) | |
| 34 #if defined(OS_WIN) | |
| 35 #pragma warning(disable: 4483) | |
| 36 extern "C" { extern void (*const __identifier("??_7TestNode@WebCore@@6B@")[])();
} | |
| 37 #else | |
| 38 extern "C" { extern void* _ZTVN7WebCore8TestNodeE[]; } | |
| 39 #endif | |
| 40 #endif // ENABLE(BINDING_INTEGRITY) | |
| 41 | |
| 42 namespace WebCore { | |
| 43 | |
| 44 #if ENABLE(BINDING_INTEGRITY) | |
| 45 // This checks if a DOM object that is about to be wrapped is valid. | |
| 46 // Specifically, it checks that a vtable of the DOM object is equal to | |
| 47 // a vtable of an expected class. | |
| 48 // Due to a dangling pointer, the DOM object you are wrapping might be | |
| 49 // already freed or realloced. If freed, the check will fail because | |
| 50 // a free list pointer should be stored at the head of the DOM object. | |
| 51 // If realloced, the check will fail because the vtable of the DOM object | |
| 52 // differs from the expected vtable (unless the same class of DOM object | |
| 53 // is realloced on the slot). | |
| 54 inline void checkTypeOrDieTrying(TestNode* object) | |
| 55 { | |
| 56 void* actualVTablePointer = *(reinterpret_cast<void**>(object)); | |
| 57 #if defined(OS_WIN) | |
| 58 void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7Test
Node@WebCore@@6B@")); | |
| 59 #else | |
| 60 void* expectedVTablePointer = &_ZTVN7WebCore8TestNodeE[2]; | |
| 61 #endif | |
| 62 if (actualVTablePointer != expectedVTablePointer) | |
| 63 CRASH(); | |
| 64 } | |
| 65 #endif // ENABLE(BINDING_INTEGRITY) | |
| 66 | |
| 67 WrapperTypeInfo V8TestNode::info = { V8TestNode::GetTemplate, V8TestNode::derefO
bject, 0, V8TestNode::toEventTarget, 0, V8TestNode::installPerContextPrototypePr
operties, &V8Node::info, WrapperTypeObjectPrototype }; | |
| 68 | |
| 69 namespace TestNodeV8Internal { | |
| 70 | |
| 71 template <typename T> void V8_USE(T) { } | |
| 72 | |
| 73 static v8::Handle<v8::Value> constructor(const v8::Arguments& args) | |
| 74 { | |
| 75 | |
| 76 RefPtr<TestNode> impl = TestNode::create(); | |
| 77 v8::Handle<v8::Object> wrapper = args.Holder(); | |
| 78 | |
| 79 V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestNode::info,
wrapper, args.GetIsolate(), WrapperConfiguration::Dependent); | |
| 80 return wrapper; | |
| 81 } | |
| 82 | |
| 83 } // namespace TestNodeV8Internal | |
| 84 | |
| 85 v8::Handle<v8::Value> V8TestNode::constructorCallback(const v8::Arguments& args) | |
| 86 { | |
| 87 if (!args.IsConstructCall()) | |
| 88 return throwTypeError("DOM object constructor cannot be called as a func
tion.", args.GetIsolate()); | |
| 89 | |
| 90 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) | |
| 91 return args.Holder(); | |
| 92 | |
| 93 return TestNodeV8Internal::constructor(args); | |
| 94 } | |
| 95 | |
| 96 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestNodeTemplate(v8::Pers
istent<v8::FunctionTemplate> desc, v8::Isolate* isolate, WrapperWorldType curren
tWorldType) | |
| 97 { | |
| 98 desc->ReadOnlyPrototype(); | |
| 99 | |
| 100 v8::Local<v8::Signature> defaultSignature; | |
| 101 defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestNode", V
8Node::GetTemplate(isolate, currentWorldType), V8TestNode::internalFieldCount, | |
| 102 0, 0, | |
| 103 0, 0, isolate, currentWorldType); | |
| 104 UNUSED_PARAM(defaultSignature); // In some cases, it will not be used. | |
| 105 desc->SetCallHandler(V8TestNode::constructorCallback); | |
| 106 | |
| 107 | |
| 108 // Custom toString template | |
| 109 desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->to
StringTemplate()); | |
| 110 return desc; | |
| 111 } | |
| 112 | |
| 113 v8::Persistent<v8::FunctionTemplate> V8TestNode::GetTemplate(v8::Isolate* isolat
e, WrapperWorldType currentWorldType) | |
| 114 { | |
| 115 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | |
| 116 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWo
rldType).find(&info); | |
| 117 if (result != data->templateMap(currentWorldType).end()) | |
| 118 return result->value; | |
| 119 | |
| 120 v8::HandleScope handleScope; | |
| 121 v8::Persistent<v8::FunctionTemplate> templ = | |
| 122 ConfigureV8TestNodeTemplate(data->rawTemplate(&info, currentWorldType),
isolate, currentWorldType); | |
| 123 data->templateMap(currentWorldType).add(&info, templ); | |
| 124 return templ; | |
| 125 } | |
| 126 | |
| 127 bool V8TestNode::HasInstance(v8::Handle<v8::Value> value, v8::Isolate* isolate,
WrapperWorldType currentWorldType) | |
| 128 { | |
| 129 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWor
ldType); | |
| 130 } | |
| 131 | |
| 132 bool V8TestNode::HasInstanceInAnyWorld(v8::Handle<v8::Value> value, v8::Isolate*
isolate) | |
| 133 { | |
| 134 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld) | |
| 135 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWo
rld) | |
| 136 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorl
d); | |
| 137 } | |
| 138 | |
| 139 EventTarget* V8TestNode::toEventTarget(v8::Handle<v8::Object> object) | |
| 140 { | |
| 141 return toNative(object); | |
| 142 } | |
| 143 | |
| 144 | |
| 145 v8::Handle<v8::Object> V8TestNode::createWrapper(PassRefPtr<TestNode> impl, v8::
Handle<v8::Object> creationContext, v8::Isolate* isolate) | |
| 146 { | |
| 147 ASSERT(impl.get()); | |
| 148 ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty()); | |
| 149 | |
| 150 #if ENABLE(BINDING_INTEGRITY) | |
| 151 checkTypeOrDieTrying(impl.get()); | |
| 152 #endif | |
| 153 ASSERT(static_cast<void*>(static_cast<Node*>(impl.get())) == static_cast<voi
d*>(impl.get())); | |
| 154 | |
| 155 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext
, &info, impl.get(), isolate); | |
| 156 if (UNLIKELY(wrapper.IsEmpty())) | |
| 157 return wrapper; | |
| 158 | |
| 159 installPerContextProperties(wrapper, impl.get(), isolate); | |
| 160 V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasD
ependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Indep
endent); | |
| 161 return wrapper; | |
| 162 } | |
| 163 void V8TestNode::derefObject(void* object) | |
| 164 { | |
| 165 static_cast<TestNode*>(object)->deref(); | |
| 166 } | |
| 167 | |
| 168 } // namespace WebCore | |
| OLD | NEW |