diff options
Diffstat (limited to 'WebCore/bindings/scripts/test')
-rw-r--r-- | WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp | 6 | ||||
-rw-r--r-- | WebCore/bindings/scripts/test/CPP/WebDOMTestObj.h | 4 | ||||
-rw-r--r-- | WebCore/bindings/scripts/test/JS/JSTestObj.cpp | 2 | ||||
-rw-r--r-- | WebCore/bindings/scripts/test/ObjC/DOMTestObj.h | 4 | ||||
-rw-r--r-- | WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm | 6 | ||||
-rw-r--r-- | WebCore/bindings/scripts/test/TestObj.idl | 10 | ||||
-rw-r--r-- | WebCore/bindings/scripts/test/V8/V8TestInterface.cpp | 22 | ||||
-rw-r--r-- | WebCore/bindings/scripts/test/V8/V8TestInterface.h | 31 | ||||
-rw-r--r-- | WebCore/bindings/scripts/test/V8/V8TestObj.cpp | 101 | ||||
-rw-r--r-- | WebCore/bindings/scripts/test/V8/V8TestObj.h | 31 |
10 files changed, 149 insertions, 68 deletions
diff --git a/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp b/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp index 9cceb3c..579295f 100644 --- a/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp +++ b/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.cpp @@ -199,7 +199,7 @@ void WebDOMTestObj::setXMLObjAttr(const WebDOMTestObj& newXMLObjAttr) impl()->setXMLObjAttr(toWebCore(newXMLObjAttr)); } -bool WebDOMTestObj::CREATE() const +bool WebDOMTestObj::create() const { if (!impl()) return false; @@ -207,12 +207,12 @@ bool WebDOMTestObj::CREATE() const return impl()->isCreate(); } -void WebDOMTestObj::setCREATE(bool newCREATE) +void WebDOMTestObj::setCreate(bool newCreate) { if (!impl()) return; - impl()->setCreate(newCREATE); + impl()->setCreate(newCreate); } WebDOMString WebDOMTestObj::reflectedStringAttr() const diff --git a/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.h b/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.h index 037a1d3..cd6caaa 100644 --- a/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.h +++ b/WebCore/bindings/scripts/test/CPP/WebDOMTestObj.h @@ -72,8 +72,8 @@ public: void setTestObjAttr(const WebDOMTestObj&); WebDOMTestObj XMLObjAttr() const; void setXMLObjAttr(const WebDOMTestObj&); - bool CREATE() const; - void setCREATE(bool); + bool create() const; + void setCreate(bool); WebDOMString reflectedStringAttr() const; void setReflectedStringAttr(const WebDOMString&); int reflectedIntegralAttr() const; diff --git a/WebCore/bindings/scripts/test/JS/JSTestObj.cpp b/WebCore/bindings/scripts/test/JS/JSTestObj.cpp index 63bc368..5236267 100644 --- a/WebCore/bindings/scripts/test/JS/JSTestObj.cpp +++ b/WebCore/bindings/scripts/test/JS/JSTestObj.cpp @@ -63,7 +63,7 @@ static const HashTableValue JSTestObjTableValues[34] = { "stringAttr", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjStringAttr), (intptr_t)setJSTestObjStringAttr THUNK_GENERATOR(0) }, { "testObjAttr", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjTestObjAttr), (intptr_t)setJSTestObjTestObjAttr THUNK_GENERATOR(0) }, { "XMLObjAttr", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjXMLObjAttr), (intptr_t)setJSTestObjXMLObjAttr THUNK_GENERATOR(0) }, - { "CREATE", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjCreate), (intptr_t)setJSTestObjCreate THUNK_GENERATOR(0) }, + { "create", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjCreate), (intptr_t)setJSTestObjCreate THUNK_GENERATOR(0) }, { "reflectedStringAttr", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjReflectedStringAttr), (intptr_t)setJSTestObjReflectedStringAttr THUNK_GENERATOR(0) }, { "reflectedIntegralAttr", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjReflectedIntegralAttr), (intptr_t)setJSTestObjReflectedIntegralAttr THUNK_GENERATOR(0) }, { "reflectedBooleanAttr", DontDelete, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjReflectedBooleanAttr), (intptr_t)setJSTestObjReflectedBooleanAttr THUNK_GENERATOR(0) }, diff --git a/WebCore/bindings/scripts/test/ObjC/DOMTestObj.h b/WebCore/bindings/scripts/test/ObjC/DOMTestObj.h index 132b215..1ad29cb 100644 --- a/WebCore/bindings/scripts/test/ObjC/DOMTestObj.h +++ b/WebCore/bindings/scripts/test/ObjC/DOMTestObj.h @@ -64,8 +64,8 @@ enum { - (void)setTestObjAttr:(DOMTestObj *)newTestObjAttr; - (DOMTestObj *)XMLObjAttr; - (void)setXMLObjAttr:(DOMTestObj *)newXMLObjAttr; -- (BOOL)CREATE; -- (void)setCREATE:(BOOL)newCREATE; +- (BOOL)create; +- (void)setCreate:(BOOL)newCreate; - (NSString *)reflectedStringAttr; - (void)setReflectedStringAttr:(NSString *)newReflectedStringAttr; - (int)reflectedIntegralAttr; diff --git a/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm b/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm index 9725b24..6788075 100644 --- a/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm +++ b/WebCore/bindings/scripts/test/ObjC/DOMTestObj.mm @@ -168,16 +168,16 @@ IMPL->setXMLObjAttr(core(newXMLObjAttr)); } -- (BOOL)CREATE +- (BOOL)create { WebCore::JSMainThreadNullState state; return IMPL->isCreate(); } -- (void)setCREATE:(BOOL)newCREATE +- (void)setCreate:(BOOL)newCreate { WebCore::JSMainThreadNullState state; - IMPL->setCreate(newCREATE); + IMPL->setCreate(newCreate); } - (NSString *)reflectedStringAttr diff --git a/WebCore/bindings/scripts/test/TestObj.idl b/WebCore/bindings/scripts/test/TestObj.idl index 89dfdf7..22ed680 100644 --- a/WebCore/bindings/scripts/test/TestObj.idl +++ b/WebCore/bindings/scripts/test/TestObj.idl @@ -44,7 +44,7 @@ module test { JS, V8 // WK_ucfirst, WK_lcfirst exceptional cases. attribute TestObj XMLObjAttr; - attribute boolean CREATE; + attribute boolean create; // Reflected DOM attributes attribute [Reflect] DOMString reflectedStringAttr; @@ -142,6 +142,14 @@ module test { [ClassMethod] void classMethod(); [ClassMethod] long classMethodWithOptional(in [Optional] long arg); +#if defined(TESTING_V8) + // 'EnabledAtRuntime' methods and attributes. + [EnabledAtRuntime] void enabledAtRuntimeMethod1(in int intArg); + [EnabledAtRuntime=FeatureName] void enabledAtRuntimeMethod2(in int intArg); + attribute [EnabledAtRuntime] long enabledAtRuntimeAttr1; + attribute [EnabledAtRuntime=FeatureName] long enabledAtRuntimeAttr2; +#endif + // ObjectiveC reserved words. readonly attribute long description; attribute long id; diff --git a/WebCore/bindings/scripts/test/V8/V8TestInterface.cpp b/WebCore/bindings/scripts/test/V8/V8TestInterface.cpp index 340dca7..267f1f0 100644 --- a/WebCore/bindings/scripts/test/V8/V8TestInterface.cpp +++ b/WebCore/bindings/scripts/test/V8/V8TestInterface.cpp @@ -70,24 +70,16 @@ v8::Persistent<v8::FunctionTemplate> V8TestInterface::GetTemplate() return V8TestInterfaceCache; } -TestInterface* V8TestInterface::toNative(v8::Handle<v8::Object> object) -{ - return reinterpret_cast<TestInterface*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex)); -} - bool V8TestInterface::HasInstance(v8::Handle<v8::Value> value) { return GetRawTemplate()->HasInstance(value); } -v8::Handle<v8::Object> V8TestInterface::wrap(TestInterface* impl) +v8::Handle<v8::Object> V8TestInterface::wrapSlow(TestInterface* impl) { v8::Handle<v8::Object> wrapper; V8Proxy* proxy = 0; - wrapper = getDOMObjectMap().get(impl); - if (!wrapper.IsEmpty()) - return wrapper; wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl); if (wrapper.IsEmpty()) return wrapper; @@ -97,18 +89,6 @@ v8::Handle<v8::Object> V8TestInterface::wrap(TestInterface* impl) return wrapper; } -v8::Handle<v8::Value> toV8(PassRefPtr<TestInterface > impl) -{ - return toV8(impl.get()); -} - -v8::Handle<v8::Value> toV8(TestInterface* impl) -{ - if (!impl) - return v8::Null(); - return V8TestInterface::wrap(impl); -} - void V8TestInterface::derefObject(void* object) { static_cast<TestInterface*>(object)->deref(); diff --git a/WebCore/bindings/scripts/test/V8/V8TestInterface.h b/WebCore/bindings/scripts/test/V8/V8TestInterface.h index afdf381..c1e319b 100644 --- a/WebCore/bindings/scripts/test/V8/V8TestInterface.h +++ b/WebCore/bindings/scripts/test/V8/V8TestInterface.h @@ -24,6 +24,7 @@ #define V8TestInterface_h #include "TestInterface.h" +#include "V8DOMWrapper.h" #include "WrapperTypeInfo.h" #include "wtf/text/StringHash.h" #include <v8.h> @@ -37,16 +38,38 @@ public: static bool HasInstance(v8::Handle<v8::Value> value); static v8::Persistent<v8::FunctionTemplate> GetRawTemplate(); static v8::Persistent<v8::FunctionTemplate> GetTemplate(); - static TestInterface* toNative(v8::Handle<v8::Object>); - static v8::Handle<v8::Object> wrap(TestInterface*); + static TestInterface* toNative(v8::Handle<v8::Object> object) + { + return reinterpret_cast<TestInterface*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex)); + } + inline static v8::Handle<v8::Object> wrap(TestInterface*); static void derefObject(void*); static WrapperTypeInfo info; static v8::Handle<v8::Value> constructorCallback(const v8::Arguments& args); static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + 0; +private: + static v8::Handle<v8::Object> wrapSlow(TestInterface*); }; -v8::Handle<v8::Value> toV8(TestInterface*); -v8::Handle<v8::Value> toV8(PassRefPtr<TestInterface >); + +v8::Handle<v8::Object> V8TestInterface::wrap(TestInterface* impl) +{ + v8::Handle<v8::Object> wrapper = getDOMObjectMap().get(impl); + if (!wrapper.IsEmpty()) + return wrapper; + return V8TestInterface::wrapSlow(impl); +} + +inline v8::Handle<v8::Value> toV8(TestInterface* impl) +{ + if (!impl) + return v8::Null(); + return V8TestInterface::wrap(impl); +} +inline v8::Handle<v8::Value> toV8(PassRefPtr< TestInterface > impl) +{ + return toV8(impl.get()); +} } #endif // V8TestInterface_h diff --git a/WebCore/bindings/scripts/test/V8/V8TestObj.cpp b/WebCore/bindings/scripts/test/V8/V8TestObj.cpp index 8f824d9..44f0d3e 100644 --- a/WebCore/bindings/scripts/test/V8/V8TestObj.cpp +++ b/WebCore/bindings/scripts/test/V8/V8TestObj.cpp @@ -35,6 +35,7 @@ #include "V8IsolatedContext.h" #include "V8Proxy.h" #include "V8TestCallback.h" +#include "V8int.h" #include "V8log.h" #include <wtf/GetPtr.h> #include <wtf/RefCounted.h> @@ -172,16 +173,16 @@ static void XMLObjAttrAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value return; } -static v8::Handle<v8::Value> CREATEAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +static v8::Handle<v8::Value> createAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { - INC_STATS("DOM.TestObj.CREATE._get"); + INC_STATS("DOM.TestObj.create._get"); TestObj* imp = V8TestObj::toNative(info.Holder()); return v8Boolean(imp->isCreate()); } -static void CREATEAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +static void createAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) { - INC_STATS("DOM.TestObj.CREATE._set"); + INC_STATS("DOM.TestObj.create._set"); TestObj* imp = V8TestObj::toNative(info.Holder()); bool v = value->BooleanValue(); imp->setCreate(v); @@ -515,6 +516,38 @@ static void conditionalAttr3AttrSetter(v8::Local<v8::String> name, v8::Local<v8: #endif // ENABLE(Condition1) || ENABLE(Condition2) +static v8::Handle<v8::Value> enabledAtRuntimeAttr1AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.enabledAtRuntimeAttr1._get"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + return v8::Integer::New(imp->enabledAtRuntimeAttr1()); +} + +static void enabledAtRuntimeAttr1AttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.enabledAtRuntimeAttr1._set"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + int v = toInt32(value); + imp->setEnabledAtRuntimeAttr1(v); + return; +} + +static v8::Handle<v8::Value> enabledAtRuntimeAttr2AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.enabledAtRuntimeAttr2._get"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + return v8::Integer::New(imp->enabledAtRuntimeAttr2()); +} + +static void enabledAtRuntimeAttr2AttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.enabledAtRuntimeAttr2._set"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + int v = toInt32(value); + imp->setEnabledAtRuntimeAttr2(v); + return; +} + static v8::Handle<v8::Value> descriptionAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.TestObj.description._get"); @@ -1020,6 +1053,24 @@ static v8::Handle<v8::Value> classMethodWithOptionalCallback(const v8::Arguments return v8::Integer::New(TestObj::classMethodWithOptional(arg)); } +static v8::Handle<v8::Value> enabledAtRuntimeMethod1Callback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.enabledAtRuntimeMethod1"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + EXCEPTION_BLOCK(int, intArg, V8int::HasInstance(args[0]) ? V8int::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0); + imp->enabledAtRuntimeMethod1(intArg); + return v8::Handle<v8::Value>(); +} + +static v8::Handle<v8::Value> enabledAtRuntimeMethod2Callback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.enabledAtRuntimeMethod2"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + EXCEPTION_BLOCK(int, intArg, V8int::HasInstance(args[0]) ? V8int::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0); + imp->enabledAtRuntimeMethod2(intArg); + return v8::Handle<v8::Value>(); +} + } // namespace TestObjInternal static const BatchedAttribute TestObjAttrs[] = { @@ -1041,8 +1092,8 @@ static const BatchedAttribute TestObjAttrs[] = { {"testObjAttr", TestObjInternal::testObjAttrAttrGetter, TestObjInternal::testObjAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, // Attribute 'XMLObjAttr' (Type: 'attribute' ExtAttr: '') {"XMLObjAttr", TestObjInternal::XMLObjAttrAttrGetter, TestObjInternal::XMLObjAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, - // Attribute 'CREATE' (Type: 'attribute' ExtAttr: '') - {"CREATE", TestObjInternal::CREATEAttrGetter, TestObjInternal::CREATEAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, + // Attribute 'create' (Type: 'attribute' ExtAttr: '') + {"create", TestObjInternal::createAttrGetter, TestObjInternal::createAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, // Attribute 'reflectedStringAttr' (Type: 'attribute' ExtAttr: 'Reflect') {"reflectedStringAttr", TestObjInternal::reflectedStringAttrAttrGetter, TestObjInternal::reflectedStringAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, // Attribute 'reflectedIntegralAttr' (Type: 'attribute' ExtAttr: 'Reflect') @@ -1157,6 +1208,18 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestObjTemplate(v8::Persi v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate(); v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate(); + if (RuntimeEnabledFeatures::enabledAtRuntimeAttr1Enabled()) { + static const BatchedAttribute attrData =\ + // Attribute 'enabledAtRuntimeAttr1' (Type: 'attribute' ExtAttr: 'EnabledAtRuntime') + {"enabledAtRuntimeAttr1", TestObjInternal::enabledAtRuntimeAttr1AttrGetter, TestObjInternal::enabledAtRuntimeAttr1AttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}; + configureAttribute(instance, proto, attrData); + } + if (RuntimeEnabledFeatures::featureNameEnabled()) { + static const BatchedAttribute attrData =\ + // Attribute 'enabledAtRuntimeAttr2' (Type: 'attribute' ExtAttr: 'EnabledAtRuntime') + {"enabledAtRuntimeAttr2", TestObjInternal::enabledAtRuntimeAttr2AttrGetter, TestObjInternal::enabledAtRuntimeAttr2AttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}; + configureAttribute(instance, proto, attrData); + } // Custom Signature 'voidMethodWithArgs' const int voidMethodWithArgsArgc = 3; @@ -1195,6 +1258,10 @@ static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestObjTemplate(v8::Persi proto->Set(v8::String::New("customArgsAndException"), v8::FunctionTemplate::New(TestObjInternal::customArgsAndExceptionCallback, v8::Handle<v8::Value>(), customArgsAndExceptionSignature)); desc->Set(v8::String::New("classMethod"), v8::FunctionTemplate::New(TestObjInternal::classMethodCallback, v8::Handle<v8::Value>(), v8::Local<v8::Signature>())); desc->Set(v8::String::New("classMethodWithOptional"), v8::FunctionTemplate::New(TestObjInternal::classMethodWithOptionalCallback, v8::Handle<v8::Value>(), v8::Local<v8::Signature>())); + if (RuntimeEnabledFeatures::enabledAtRuntimeMethod1Enabled()) + proto->Set(v8::String::New("enabledAtRuntimeMethod1"), v8::FunctionTemplate::New(TestObjInternal::enabledAtRuntimeMethod1Callback, v8::Handle<v8::Value>(), defaultSignature)); + if (RuntimeEnabledFeatures::featureNameEnabled()) + proto->Set(v8::String::New("enabledAtRuntimeMethod2"), v8::FunctionTemplate::New(TestObjInternal::enabledAtRuntimeMethod2Callback, v8::Handle<v8::Value>(), defaultSignature)); batchConfigureConstants(desc, proto, TestObjConsts, sizeof(TestObjConsts) / sizeof(*TestObjConsts)); // Custom toString template @@ -1214,24 +1281,16 @@ v8::Persistent<v8::FunctionTemplate> V8TestObj::GetTemplate() return V8TestObjCache; } -TestObj* V8TestObj::toNative(v8::Handle<v8::Object> object) -{ - return reinterpret_cast<TestObj*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex)); -} - bool V8TestObj::HasInstance(v8::Handle<v8::Value> value) { return GetRawTemplate()->HasInstance(value); } -v8::Handle<v8::Object> V8TestObj::wrap(TestObj* impl) +v8::Handle<v8::Object> V8TestObj::wrapSlow(TestObj* impl) { v8::Handle<v8::Object> wrapper; V8Proxy* proxy = 0; - wrapper = getDOMObjectMap().get(impl); - if (!wrapper.IsEmpty()) - return wrapper; wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl); if (wrapper.IsEmpty()) return wrapper; @@ -1241,18 +1300,6 @@ v8::Handle<v8::Object> V8TestObj::wrap(TestObj* impl) return wrapper; } -v8::Handle<v8::Value> toV8(PassRefPtr<TestObj > impl) -{ - return toV8(impl.get()); -} - -v8::Handle<v8::Value> toV8(TestObj* impl) -{ - if (!impl) - return v8::Null(); - return V8TestObj::wrap(impl); -} - void V8TestObj::derefObject(void* object) { static_cast<TestObj*>(object)->deref(); diff --git a/WebCore/bindings/scripts/test/V8/V8TestObj.h b/WebCore/bindings/scripts/test/V8/V8TestObj.h index d9715c9..1e60488 100644 --- a/WebCore/bindings/scripts/test/V8/V8TestObj.h +++ b/WebCore/bindings/scripts/test/V8/V8TestObj.h @@ -22,6 +22,7 @@ #define V8TestObj_h #include "TestObj.h" +#include "V8DOMWrapper.h" #include "WrapperTypeInfo.h" #include "wtf/text/StringHash.h" #include <v8.h> @@ -35,8 +36,11 @@ public: static bool HasInstance(v8::Handle<v8::Value> value); static v8::Persistent<v8::FunctionTemplate> GetRawTemplate(); static v8::Persistent<v8::FunctionTemplate> GetTemplate(); - static TestObj* toNative(v8::Handle<v8::Object>); - static v8::Handle<v8::Object> wrap(TestObj*); + static TestObj* toNative(v8::Handle<v8::Object> object) + { + return reinterpret_cast<TestObj*>(object->GetPointerFromInternalField(v8DOMWrapperObjectIndex)); + } + inline static v8::Handle<v8::Object> wrap(TestObj*); static void derefObject(void*); static WrapperTypeInfo info; static v8::Handle<v8::Value> customMethodCallback(const v8::Arguments&); @@ -44,10 +48,29 @@ public: static v8::Handle<v8::Value> customAttrAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info); static void customAttrAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info); static const int internalFieldCount = v8DefaultWrapperInternalFieldCount + 0; +private: + static v8::Handle<v8::Object> wrapSlow(TestObj*); }; -v8::Handle<v8::Value> toV8(TestObj*); -v8::Handle<v8::Value> toV8(PassRefPtr<TestObj >); + +v8::Handle<v8::Object> V8TestObj::wrap(TestObj* impl) +{ + v8::Handle<v8::Object> wrapper = getDOMObjectMap().get(impl); + if (!wrapper.IsEmpty()) + return wrapper; + return V8TestObj::wrapSlow(impl); +} + +inline v8::Handle<v8::Value> toV8(TestObj* impl) +{ + if (!impl) + return v8::Null(); + return V8TestObj::wrap(impl); +} +inline v8::Handle<v8::Value> toV8(PassRefPtr< TestObj > impl) +{ + return toV8(impl.get()); +} } #endif // V8TestObj_h |