OLD | NEW |
(Empty) | |
| 1 /* |
| 2 This file is part of the Blink open source project. |
| 3 This file has been auto-generated by CodeGeneratorV8.pm. 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 "V8TestInterfaceImplementedAs.h" |
| 23 |
| 24 #include "RuntimeEnabledFeatures.h" |
| 25 #include "bindings/v8/ScriptController.h" |
| 26 #include "bindings/v8/V8Binding.h" |
| 27 #include "bindings/v8/V8DOMConfiguration.h" |
| 28 #include "bindings/v8/V8DOMWrapper.h" |
| 29 #include "core/dom/ContextFeatures.h" |
| 30 #include "core/dom/Document.h" |
| 31 #include "core/dom/ExceptionCode.h" |
| 32 #include "core/page/Frame.h" |
| 33 #include "wtf/GetPtr.h" |
| 34 #include "wtf/RefCounted.h" |
| 35 #include "wtf/RefPtr.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("??_7RealClass@WebCore@@6B@")[])()
; } |
| 42 #else |
| 43 extern "C" { extern void* _ZTVN7WebCore9RealClassE[]; } |
| 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(RealClass* object) |
| 60 { |
| 61 void* actualVTablePointer = *(reinterpret_cast<void**>(object)); |
| 62 #if defined(OS_WIN) |
| 63 void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7Real
Class@WebCore@@6B@")); |
| 64 #else |
| 65 void* expectedVTablePointer = &_ZTVN7WebCore9RealClassE[2]; |
| 66 #endif |
| 67 if (actualVTablePointer != expectedVTablePointer) |
| 68 CRASH(); |
| 69 } |
| 70 #endif // ENABLE(BINDING_INTEGRITY) |
| 71 |
| 72 #if defined(OS_WIN) |
| 73 // In ScriptWrappable, the use of extern function prototypes inside templated st
atic methods has an issue on windows. |
| 74 // These prototypes do not pick up the surrounding namespace, so drop out of Web
Core as a workaround. |
| 75 } // namespace WebCore |
| 76 using WebCore::ScriptWrappable; |
| 77 using WebCore::V8TestInterfaceImplementedAs; |
| 78 using WebCore::RealClass; |
| 79 #endif |
| 80 void initializeScriptWrappableForInterface(RealClass* object) |
| 81 { |
| 82 if (ScriptWrappable::wrapperCanBeStoredInObject(object)) |
| 83 ScriptWrappable::setTypeInfoInObject(object, &V8TestInterfaceImplemented
As::info); |
| 84 } |
| 85 #if defined(OS_WIN) |
| 86 namespace WebCore { |
| 87 #endif |
| 88 WrapperTypeInfo V8TestInterfaceImplementedAs::info = { V8TestInterfaceImplemente
dAs::GetTemplate, V8TestInterfaceImplementedAs::derefObject, 0, 0, 0, V8TestInte
rfaceImplementedAs::installPerContextPrototypeProperties, 0, WrapperTypeObjectPr
ototype }; |
| 89 |
| 90 namespace TestInterfaceImplementedAsV8Internal { |
| 91 |
| 92 template <typename T> void V8_USE(T) { } |
| 93 |
| 94 static v8::Handle<v8::Value> aAttrGetter(v8::Local<v8::String> name, const v8::A
ccessorInfo& info) |
| 95 { |
| 96 RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder()); |
| 97 return v8String(imp->a(), info.GetIsolate(), ReturnUnsafeHandle); |
| 98 } |
| 99 |
| 100 static v8::Handle<v8::Value> aAttrGetterCallback(v8::Local<v8::String> name, con
st v8::AccessorInfo& info) |
| 101 { |
| 102 return RealClassV8Internal::aAttrGetter(name, info); |
| 103 } |
| 104 |
| 105 static void aAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value,
const v8::AccessorInfo& info) |
| 106 { |
| 107 RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder()); |
| 108 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, v, value); |
| 109 imp->setA(v); |
| 110 return; |
| 111 } |
| 112 |
| 113 static void aAttrSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value>
value, const v8::AccessorInfo& info) |
| 114 { |
| 115 RealClassV8Internal::aAttrSetter(name, value, info); |
| 116 } |
| 117 |
| 118 static v8::Handle<v8::Value> bAttrGetter(v8::Local<v8::String> name, const v8::A
ccessorInfo& info) |
| 119 { |
| 120 RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder()); |
| 121 return toV8Fast(imp->b(), info, imp); |
| 122 } |
| 123 |
| 124 static v8::Handle<v8::Value> bAttrGetterCallback(v8::Local<v8::String> name, con
st v8::AccessorInfo& info) |
| 125 { |
| 126 return RealClassV8Internal::bAttrGetter(name, info); |
| 127 } |
| 128 |
| 129 static void bAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value,
const v8::AccessorInfo& info) |
| 130 { |
| 131 RealClass* imp = V8TestInterfaceImplementedAs::toNative(info.Holder()); |
| 132 V8TRYCATCH_VOID(RealClass*, v, V8TestInterfaceImplementedAs::HasInstance(val
ue, info.GetIsolate(), worldType(info.GetIsolate())) ? V8TestInterfaceImplemente
dAs::toNative(v8::Handle<v8::Object>::Cast(value)) : 0); |
| 133 imp->setB(WTF::getPtr(v)); |
| 134 return; |
| 135 } |
| 136 |
| 137 static void bAttrSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value>
value, const v8::AccessorInfo& info) |
| 138 { |
| 139 RealClassV8Internal::bAttrSetter(name, value, info); |
| 140 } |
| 141 |
| 142 static v8::Handle<v8::Value> func1Method(const v8::Arguments& args) |
| 143 { |
| 144 if (args.Length() < 1) |
| 145 return throwNotEnoughArgumentsError(args.GetIsolate()); |
| 146 RealClass* imp = V8TestInterfaceImplementedAs::toNative(args.Holder()); |
| 147 V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, a, args[0]); |
| 148 return v8String(imp->func1(a), args.GetIsolate(), ReturnUnsafeHandle); |
| 149 } |
| 150 |
| 151 static v8::Handle<v8::Value> func1MethodCallback(const v8::Arguments& args) |
| 152 { |
| 153 return RealClassV8Internal::func1Method(args); |
| 154 } |
| 155 |
| 156 static v8::Handle<v8::Value> funcTestInterfaceImplementedAsParamMethod(const v8:
:Arguments& args) |
| 157 { |
| 158 if (args.Length() < 1) |
| 159 return throwNotEnoughArgumentsError(args.GetIsolate()); |
| 160 RealClass* imp = V8TestInterfaceImplementedAs::toNative(args.Holder()); |
| 161 V8TRYCATCH(RealClass*, orange, V8TestInterfaceImplementedAs::HasInstance(arg
s[0], args.GetIsolate(), worldType(args.GetIsolate())) ? V8TestInterfaceImplemen
tedAs::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0); |
| 162 return v8String(imp->funcTestInterfaceImplementedAsParam(orange), args.GetIs
olate(), ReturnUnsafeHandle); |
| 163 } |
| 164 |
| 165 static v8::Handle<v8::Value> funcTestInterfaceImplementedAsParamMethodCallback(c
onst v8::Arguments& args) |
| 166 { |
| 167 return RealClassV8Internal::funcTestInterfaceImplementedAsParamMethod(args); |
| 168 } |
| 169 |
| 170 } // namespace TestInterfaceImplementedAsV8Internal |
| 171 |
| 172 static const V8DOMConfiguration::BatchedAttribute V8TestInterfaceImplementedAsAt
trs[] = { |
| 173 // Attribute 'a' (Type: 'attribute' ExtAttr: '') |
| 174 {"a", RealClassV8Internal::aAttrGetterCallback, RealClassV8Internal::aAttrSe
tterCallback, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT)
, static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, |
| 175 // Attribute 'b' (Type: 'attribute' ExtAttr: '') |
| 176 {"b", RealClassV8Internal::bAttrGetterCallback, RealClassV8Internal::bAttrSe
tterCallback, 0, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT)
, static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, |
| 177 }; |
| 178 |
| 179 static const V8DOMConfiguration::BatchedMethod V8TestInterfaceImplementedAsMetho
ds[] = { |
| 180 {"func1", RealClassV8Internal::func1MethodCallback, 0, 1}, |
| 181 }; |
| 182 |
| 183 static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestInterfaceImplementedA
sTemplate(v8::Persistent<v8::FunctionTemplate> desc, v8::Isolate* isolate, Wrapp
erWorldType currentWorldType) |
| 184 { |
| 185 desc->ReadOnlyPrototype(); |
| 186 |
| 187 v8::Local<v8::Signature> defaultSignature; |
| 188 defaultSignature = V8DOMConfiguration::configureTemplate(desc, "TestInterfac
eImplementedAs", v8::Persistent<v8::FunctionTemplate>(), V8TestInterfaceImplemen
tedAs::internalFieldCount, |
| 189 V8TestInterfaceImplementedAsAttrs, WTF_ARRAY_LENGTH(V8TestInterfaceImple
mentedAsAttrs), |
| 190 V8TestInterfaceImplementedAsMethods, WTF_ARRAY_LENGTH(V8TestInterfaceImp
lementedAsMethods), isolate, currentWorldType); |
| 191 UNUSED_PARAM(defaultSignature); // In some cases, it will not be used. |
| 192 v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate(); |
| 193 v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate(); |
| 194 UNUSED_PARAM(instance); // In some cases, it will not be used. |
| 195 UNUSED_PARAM(proto); // In some cases, it will not be used. |
| 196 |
| 197 // Custom Signature 'funcTestInterfaceImplementedAsParam' |
| 198 const int funcTestInterfaceImplementedAsParamArgc = 1; |
| 199 v8::Handle<v8::FunctionTemplate> funcTestInterfaceImplementedAsParamArgv[fun
cTestInterfaceImplementedAsParamArgc] = { V8PerIsolateData::from(isolate)->rawTe
mplate(&V8TestInterfaceImplementedAs::info, currentWorldType) }; |
| 200 v8::Handle<v8::Signature> funcTestInterfaceImplementedAsParamSignature = v8:
:Signature::New(desc, funcTestInterfaceImplementedAsParamArgc, funcTestInterface
ImplementedAsParamArgv); |
| 201 proto->Set(v8::String::NewSymbol("funcTestInterfaceImplementedAsParam"), v8:
:FunctionTemplate::New(RealClassV8Internal::funcTestInterfaceImplementedAsParamM
ethodCallback, v8Undefined(), funcTestInterfaceImplementedAsParamSignature, 1)); |
| 202 |
| 203 // Custom toString template |
| 204 desc->Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->to
StringTemplate()); |
| 205 return desc; |
| 206 } |
| 207 |
| 208 v8::Persistent<v8::FunctionTemplate> V8TestInterfaceImplementedAs::GetTemplate(v
8::Isolate* isolate, WrapperWorldType currentWorldType) |
| 209 { |
| 210 V8PerIsolateData* data = V8PerIsolateData::from(isolate); |
| 211 V8PerIsolateData::TemplateMap::iterator result = data->templateMap(currentWo
rldType).find(&info); |
| 212 if (result != data->templateMap(currentWorldType).end()) |
| 213 return result->value; |
| 214 |
| 215 v8::HandleScope handleScope; |
| 216 v8::Persistent<v8::FunctionTemplate> templ = |
| 217 ConfigureV8TestInterfaceImplementedAsTemplate(data->rawTemplate(&info, c
urrentWorldType), isolate, currentWorldType); |
| 218 data->templateMap(currentWorldType).add(&info, templ); |
| 219 return templ; |
| 220 } |
| 221 |
| 222 bool V8TestInterfaceImplementedAs::HasInstance(v8::Handle<v8::Value> value, v8::
Isolate* isolate, WrapperWorldType currentWorldType) |
| 223 { |
| 224 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, currentWor
ldType); |
| 225 } |
| 226 |
| 227 bool V8TestInterfaceImplementedAs::HasInstanceInAnyWorld(v8::Handle<v8::Value> v
alue, v8::Isolate* isolate) |
| 228 { |
| 229 return V8PerIsolateData::from(isolate)->hasInstance(&info, value, MainWorld) |
| 230 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, IsolatedWo
rld) |
| 231 || V8PerIsolateData::from(isolate)->hasInstance(&info, value, WorkerWorl
d); |
| 232 } |
| 233 |
| 234 |
| 235 v8::Handle<v8::Object> V8TestInterfaceImplementedAs::createWrapper(PassRefPtr<Re
alClass> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
| 236 { |
| 237 ASSERT(impl.get()); |
| 238 ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty()); |
| 239 |
| 240 #if ENABLE(BINDING_INTEGRITY) |
| 241 checkTypeOrDieTrying(impl.get()); |
| 242 #endif |
| 243 |
| 244 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext
, &info, impl.get(), isolate); |
| 245 if (UNLIKELY(wrapper.IsEmpty())) |
| 246 return wrapper; |
| 247 |
| 248 installPerContextProperties(wrapper, impl.get(), isolate); |
| 249 V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate, hasD
ependentLifetime ? WrapperConfiguration::Dependent : WrapperConfiguration::Indep
endent); |
| 250 return wrapper; |
| 251 } |
| 252 void V8TestInterfaceImplementedAs::derefObject(void* object) |
| 253 { |
| 254 static_cast<RealClass*>(object)->deref(); |
| 255 } |
| 256 |
| 257 } // namespace WebCore |
OLD | NEW |