Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: Source/WebCore/bindings/scripts/test/V8/V8TestOverloadedConstructors.cpp

Issue 13937004: Move bindings-tests to bindings/tests (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "V8TestOverloadedConstructors.h"
23
24 #include "BindingState.h"
25 #include "ContextFeatures.h"
26 #include "ExceptionCode.h"
27 #include "Frame.h"
28 #include "RuntimeEnabledFeatures.h"
29 #include "V8ArrayBuffer.h"
30 #include "V8ArrayBufferView.h"
31 #include "V8Binding.h"
32 #include "V8Blob.h"
33 #include "V8DOMWrapper.h"
34 #include <wtf/ArrayBuffer.h>
35 #include <wtf/ArrayBufferView.h>
36 #include <wtf/UnusedParam.h>
37
38 #if ENABLE(BINDING_INTEGRITY)
39 #if defined(OS_WIN)
40 #pragma warning(disable: 4483)
41 extern "C" { extern void (*const __identifier("??_7TestOverloadedConstructors@We bCore@@6B@")[])(); }
42 #else
43 extern "C" { extern void* _ZTVN7WebCore26TestOverloadedConstructorsE[]; }
44 #endif
45 #endif // ENABLE(BINDING_INTEGRITY)
46
47 namespace WebCore {
48
49 #if ENABLE(BINDING_INTEGRITY)
50 // This checks if a DOM object that is about to be wrapped is valid.
51 // Specifically, it checks that a vtable of the DOM object is equal to
52 // a vtable of an expected class.
53 // Due to a dangling pointer, the DOM object you are wrapping might be
54 // already freed or realloced. If freed, the check will fail because
55 // a free list pointer should be stored at the head of the DOM object.
56 // If realloced, the check will fail because the vtable of the DOM object
57 // differs from the expected vtable (unless the same class of DOM object
58 // is realloced on the slot).
59 inline void checkTypeOrDieTrying(TestOverloadedConstructors* object)
60 {
61 void* actualVTablePointer = *(reinterpret_cast<void**>(object));
62 #if defined(OS_WIN)
63 void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7Test OverloadedConstructors@WebCore@@6B@"));
64 #else
65 void* expectedVTablePointer = &_ZTVN7WebCore26TestOverloadedConstructorsE[2] ;
66 #endif
67 if (actualVTablePointer != expectedVTablePointer)
68 CRASH();
69 }
70 #endif // ENABLE(BINDING_INTEGRITY)
71
72 WrapperTypeInfo V8TestOverloadedConstructors::info = { V8TestOverloadedConstruct ors::GetTemplate, V8TestOverloadedConstructors::derefObject, 0, 0, 0, V8TestOver loadedConstructors::installPerContextPrototypeProperties, 0, WrapperTypeObjectPr ototype };
73
74 namespace TestOverloadedConstructorsV8Internal {
75
76 template <typename T> void V8_USE(T) { }
77
78 static v8::Handle<v8::Value> constructor1(const v8::Arguments& args)
79 {
80 V8TRYCATCH(ArrayBuffer*, arrayBuffer, V8ArrayBuffer::HasInstance(args[0], ar gs.GetIsolate(), worldType(args.GetIsolate())) ? V8ArrayBuffer::toNative(v8::Han dle<v8::Object>::Cast(args[0])) : 0);
81
82 RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create (arrayBuffer);
83 v8::Handle<v8::Object> wrapper = args.Holder();
84
85 V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestOverloadedCo nstructors::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
86 return wrapper;
87 }
88
89 static v8::Handle<v8::Value> constructor2(const v8::Arguments& args)
90 {
91 V8TRYCATCH(ArrayBufferView*, arrayBufferView, V8ArrayBufferView::HasInstance (args[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8ArrayBufferView:: toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0);
92
93 RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create (arrayBufferView);
94 v8::Handle<v8::Object> wrapper = args.Holder();
95
96 V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestOverloadedCo nstructors::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
97 return wrapper;
98 }
99
100 static v8::Handle<v8::Value> constructor3(const v8::Arguments& args)
101 {
102 V8TRYCATCH(Blob*, blob, V8Blob::HasInstance(args[0], args.GetIsolate(), worl dType(args.GetIsolate())) ? V8Blob::toNative(v8::Handle<v8::Object>::Cast(args[0 ])) : 0);
103
104 RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create (blob);
105 v8::Handle<v8::Object> wrapper = args.Holder();
106
107 V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestOverloadedCo nstructors::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
108 return wrapper;
109 }
110
111 static v8::Handle<v8::Value> constructor4(const v8::Arguments& args)
112 {
113 V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, string, args[0]);
114
115 RefPtr<TestOverloadedConstructors> impl = TestOverloadedConstructors::create (string);
116 v8::Handle<v8::Object> wrapper = args.Holder();
117
118 V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestOverloadedCo nstructors::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
119 return wrapper;
120 }
121
122 static v8::Handle<v8::Value> constructor(const v8::Arguments& args)
123 {
124 if ((args.Length() == 1 && (V8ArrayBuffer::HasInstance(args[0], args.GetIsol ate(), worldType(args.GetIsolate())))))
125 return TestOverloadedConstructorsV8Internal::constructor1(args);
126 if ((args.Length() == 1 && (V8ArrayBufferView::HasInstance(args[0], args.Get Isolate(), worldType(args.GetIsolate())))))
127 return TestOverloadedConstructorsV8Internal::constructor2(args);
128 if ((args.Length() == 1 && (V8Blob::HasInstance(args[0], args.GetIsolate(), worldType(args.GetIsolate())))))
129 return TestOverloadedConstructorsV8Internal::constructor3(args);
130 if (args.Length() == 1)
131 return TestOverloadedConstructorsV8Internal::constructor4(args);
132 if (args.Length() < 1)
133 return throwNotEnoughArgumentsError(args.GetIsolate());
134 return throwTypeError(0, args.GetIsolate());
135 }
136
137 } // namespace TestOverloadedConstructorsV8Internal
138
139 v8::Handle<v8::Value> V8TestOverloadedConstructors::constructorCallback(const v8 ::Arguments& args)
140 {
141 if (!args.IsConstructCall())
142 return throwTypeError("DOM object constructor cannot be called as a func tion.", args.GetIsolate());
143
144 if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
145 return args.Holder();
146
147 return TestOverloadedConstructorsV8Internal::constructor(args);
148 }
149
150 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestOverloadedConstructor sTemplate(v8::Persistent<v8::FunctionTemplate> desc, v8::Isolate* isolate, Wrapp erWorldType currentWorldType)
151 {
152 desc->ReadOnlyPrototype();
153
154 v8::Local<v8::Signature> defaultSignature;
155 defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestOverload edConstructors", v8::Persistent<v8::FunctionTemplate>(), V8TestOverloadedConstru ctors::internalFieldCount,
156 0, 0,
157 0, 0, isolate, currentWorldType);
158 UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
159 desc->SetCallHandler(V8TestOverloadedConstructors::constructorCallback);
160
161
162 // Custom toString template
163 desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->to StringTemplate());
164 return desc;
165 }
166
167 v8::Persistent<v8::FunctionTemplate> V8TestOverloadedConstructors::GetTemplate(v 8::Isolate* isolate, WrapperWorldType currentWorldType)
168 {
169 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
170 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWo rldType).find(&info);
171 if (result != data->templateMap(currentWorldType).end())
172 return result->value;
173
174 v8::HandleScope handleScope;
175 v8::Persistent<v8::FunctionTemplate> templ =
176 ConfigureV8TestOverloadedConstructorsTemplate(data->rawTemplate(&info, c urrentWorldType), isolate, currentWorldType);
177 data->templateMap(currentWorldType).add(&info, templ);
178 return templ;
179 }
180
181 bool V8TestOverloadedConstructors::HasInstance(v8::Handle<v8::Value> value, v8:: Isolate* isolate, WrapperWorldType currentWorldType)
182 {
183 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWor ldType);
184 }
185
186 bool V8TestOverloadedConstructors::HasInstanceInAnyWorld(v8::Handle<v8::Value> v alue, v8::Isolate* isolate)
187 {
188 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld)
189 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWo rld)
190 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorl d);
191 }
192
193
194 v8::Handle<v8::Object> V8TestOverloadedConstructors::createWrapper(PassRefPtr<Te stOverloadedConstructors> impl, v8::Handle<v8::Object> creationContext, v8::Isol ate* isolate)
195 {
196 ASSERT(impl.get());
197 ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty());
198
199 #if ENABLE(BINDING_INTEGRITY)
200 checkTypeOrDieTrying(impl.get());
201 #endif
202
203 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext , &info, impl.get(), isolate);
204 if (UNLIKELY(wrapper.IsEmpty()))
205 return wrapper;
206
207 installPerContextProperties(wrapper, impl.get(), isolate);
208 V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasD ependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Indep endent);
209 return wrapper;
210 }
211 void V8TestOverloadedConstructors::derefObject(void* object)
212 {
213 static_cast<TestOverloadedConstructors*>(object)->deref();
214 }
215
216 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698