diff options
Diffstat (limited to 'WebCore/bindings/v8/test')
-rw-r--r-- | WebCore/bindings/v8/test/TestObj.idl | 71 | ||||
-rw-r--r-- | WebCore/bindings/v8/test/V8TestObj.cpp | 459 | ||||
-rw-r--r-- | WebCore/bindings/v8/test/V8TestObj.h | 53 | ||||
-rw-r--r-- | WebCore/bindings/v8/test/run_tests.py | 58 |
4 files changed, 641 insertions, 0 deletions
diff --git a/WebCore/bindings/v8/test/TestObj.idl b/WebCore/bindings/v8/test/TestObj.idl new file mode 100644 index 0000000..662ac64 --- /dev/null +++ b/WebCore/bindings/v8/test/TestObj.idl @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary formstrArg, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIEstrArg, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// This IDL file is for testing the V8 generator and for tracking changes +// in its ouput. +module test { + interface TestObj { + // Attributes + readonly attribute long readOnlyIntAttr; + readonly attribute DOMString readOnlyStringAttr; + readonly attribute TestObj readOnlyTestObjAttr; + attribute long intAttr; + attribute DOMString stringAttr; + attribute TestObj testObjAttr; + + // Methods + void voidMethod(); + void voidMethodWithArgs(in long intArg, in DOMString strArg, in TestObj objArg); + long intMethod(); + long intMethodWithArgs(in long intArg, in DOMString strArg, in TestObj objArg); + TestObj objMethod(); + TestObj objMethodWithArgs(in long intArg, in DOMString strArg, in TestObj objArg); + + // Exceptions + void methodWithException() raises(DOMException); + attribute long attrWithException raises(DOMException); + attribute long attrWithSetterException getraises(DOMException); + attribute long attrWithGetterException setraises(DOMException); + + // 'Custom' extended attribute + attribute [Custom] long customAttr; + [Custom] void customMethod(); + [Custom] void customMethodWithArgs(in long intArg, in DOMString strArg, in TestObj objArg); + + // 'Optional' extended attribute + void methodWithOptionalArg(in [Optional] long opt); + void methodWithNonOptionalArgAndOptionalArg(in long nonOpt, in [Optional] long opt); + void methodWithNonOptionalArgAndTwoOptionalArgs(in long nonOpt, in [Optional] long opt1, in long opt2); + + // Overloads + void overloadedMethod(in TestObj objArg, in DOMString strArg); + void overloadedMethod(in TestObj objArg, in [Optional] long intArg); + void overloadedMethod(in DOMString strArg); + void overloadedMethod(in long intArg); + }; +} diff --git a/WebCore/bindings/v8/test/V8TestObj.cpp b/WebCore/bindings/v8/test/V8TestObj.cpp new file mode 100644 index 0000000..d51884e --- /dev/null +++ b/WebCore/bindings/v8/test/V8TestObj.cpp @@ -0,0 +1,459 @@ +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include "config.h" +#include "V8TestObj.h" + +#include "ExceptionCode.h" +#include "RuntimeEnabledFeatures.h" +#include "V8Binding.h" +#include "V8BindingState.h" +#include "V8DOMWrapper.h" +#include "V8IsolatedContext.h" +#include "V8Proxy.h" +#include <wtf/GetPtr.h> +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + +WrapperTypeInfo V8TestObj::info = { V8TestObj::GetTemplate, V8TestObj::derefObject, 0 }; + +namespace TestObjInternal { + +template <typename T> void V8_USE(T) { } + +static v8::Handle<v8::Value> readOnlyIntAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.readOnlyIntAttr._get"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + return v8::Integer::New(imp->readOnlyIntAttr()); +} + +static v8::Handle<v8::Value> readOnlyStringAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.readOnlyStringAttr._get"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + return v8String(imp->readOnlyStringAttr()); +} + +static v8::Handle<v8::Value> readOnlyTestObjAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.readOnlyTestObjAttr._get"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + RefPtr<TestObj> result = imp->readOnlyTestObjAttr(); + v8::Handle<v8::Value> wrapper = result.get() ? getDOMObjectMap().get(result.get()) : v8::Handle<v8::Value>(); + if (wrapper.IsEmpty()) { + wrapper = toV8(result.get()); + if (!wrapper.IsEmpty()) + V8DOMWrapper::setHiddenReference(info.Holder(), wrapper); + } + return wrapper; +} + +static v8::Handle<v8::Value> intAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.intAttr._get"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + return v8::Integer::New(imp->intAttr()); +} + +static void intAttrAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.intAttr._set"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + int v = toInt32(value); + imp->setIntAttr(v); + return; +} + +static v8::Handle<v8::Value> stringAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.stringAttr._get"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + return v8String(imp->stringAttr()); +} + +static void stringAttrAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.stringAttr._set"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + V8Parameter<> v = value; + imp->setStringAttr(v); + return; +} + +static v8::Handle<v8::Value> testObjAttrAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.testObjAttr._get"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + return toV8(imp->testObjAttr()); +} + +static void testObjAttrAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.testObjAttr._set"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + TestObj* v = V8TestObj::HasInstance(value) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(value)) : 0; + imp->setTestObjAttr(WTF::getPtr(v)); + return; +} + +static v8::Handle<v8::Value> attrWithExceptionAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.attrWithException._get"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + return v8::Integer::New(imp->attrWithException()); +} + +static void attrWithExceptionAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.attrWithException._set"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + int v = toInt32(value); + imp->setAttrWithException(v); + return; +} + +static v8::Handle<v8::Value> attrWithSetterExceptionAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.attrWithSetterException._get"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + return v8::Integer::New(imp->attrWithSetterException()); +} + +static void attrWithSetterExceptionAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.attrWithSetterException._set"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + int v = toInt32(value); + imp->setAttrWithSetterException(v); + return; +} + +static v8::Handle<v8::Value> attrWithGetterExceptionAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.attrWithGetterException._get"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + return v8::Integer::New(imp->attrWithGetterException()); +} + +static void attrWithGetterExceptionAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) +{ + INC_STATS("DOM.TestObj.attrWithGetterException._set"); + TestObj* imp = V8TestObj::toNative(info.Holder()); + int v = toInt32(value); + imp->setAttrWithGetterException(v); + return; +} + +static v8::Handle<v8::Value> voidMethodCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.voidMethod"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + imp->voidMethod(); + return v8::Handle<v8::Value>(); +} + +static v8::Handle<v8::Value> voidMethodWithArgsCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.voidMethodWithArgs"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + int intArg = toInt32(args[0]); + V8Parameter<> strArg = args[1]; + TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0; + imp->voidMethodWithArgs(intArg, strArg, objArg); + return v8::Handle<v8::Value>(); +} + +static v8::Handle<v8::Value> intMethodCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.intMethod"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + return v8::Integer::New(imp->intMethod()); +} + +static v8::Handle<v8::Value> intMethodWithArgsCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.intMethodWithArgs"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + int intArg = toInt32(args[0]); + V8Parameter<> strArg = args[1]; + TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0; + return v8::Integer::New(imp->intMethodWithArgs(intArg, strArg, objArg)); +} + +static v8::Handle<v8::Value> objMethodCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.objMethod"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + return toV8(imp->objMethod()); +} + +static v8::Handle<v8::Value> objMethodWithArgsCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.objMethodWithArgs"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + int intArg = toInt32(args[0]); + V8Parameter<> strArg = args[1]; + TestObj* objArg = V8TestObj::HasInstance(args[2]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[2])) : 0; + return toV8(imp->objMethodWithArgs(intArg, strArg, objArg)); +} + +static v8::Handle<v8::Value> methodWithExceptionCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.methodWithException"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + ExceptionCode ec = 0; + { + imp->methodWithException(ec); + if (UNLIKELY(ec)) + goto fail; + return v8::Handle<v8::Value>(); + } + fail: + V8Proxy::setDOMException(ec); + return v8::Handle<v8::Value>(); +} + +static v8::Handle<v8::Value> methodWithOptionalArgCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.methodWithOptionalArg"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + if (args.Length() <= 0) { + imp->methodWithOptionalArg(); + return v8::Handle<v8::Value>(); + } + int opt = toInt32(args[0]); + imp->methodWithOptionalArg(opt); + return v8::Handle<v8::Value>(); +} + +static v8::Handle<v8::Value> methodWithNonOptionalArgAndOptionalArgCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.methodWithNonOptionalArgAndOptionalArg"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + int nonOpt = toInt32(args[0]); + if (args.Length() <= 1) { + imp->methodWithNonOptionalArgAndOptionalArg(nonOpt); + return v8::Handle<v8::Value>(); + } + int opt = toInt32(args[1]); + imp->methodWithNonOptionalArgAndOptionalArg(nonOpt, opt); + return v8::Handle<v8::Value>(); +} + +static v8::Handle<v8::Value> methodWithNonOptionalArgAndTwoOptionalArgsCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.methodWithNonOptionalArgAndTwoOptionalArgs"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + int nonOpt = toInt32(args[0]); + if (args.Length() <= 1) { + imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt); + return v8::Handle<v8::Value>(); + } + int opt1 = toInt32(args[1]); + int opt2 = toInt32(args[2]); + imp->methodWithNonOptionalArgAndTwoOptionalArgs(nonOpt, opt1, opt2); + return v8::Handle<v8::Value>(); +} + +static v8::Handle<v8::Value> overloadedMethod1Callback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.overloadedMethod1"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + TestObj* objArg = V8TestObj::HasInstance(args[0]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; + V8Parameter<> strArg = args[1]; + imp->overloadedMethod(objArg, strArg); + return v8::Handle<v8::Value>(); +} + +static v8::Handle<v8::Value> overloadedMethod2Callback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.overloadedMethod2"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + TestObj* objArg = V8TestObj::HasInstance(args[0]) ? V8TestObj::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0; + if (args.Length() <= 1) { + imp->overloadedMethod(objArg); + return v8::Handle<v8::Value>(); + } + int intArg = toInt32(args[1]); + imp->overloadedMethod(objArg, intArg); + return v8::Handle<v8::Value>(); +} + +static v8::Handle<v8::Value> overloadedMethod3Callback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.overloadedMethod3"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + V8Parameter<> strArg = args[0]; + imp->overloadedMethod(strArg); + return v8::Handle<v8::Value>(); +} + +static v8::Handle<v8::Value> overloadedMethod4Callback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.overloadedMethod4"); + TestObj* imp = V8TestObj::toNative(args.Holder()); + int intArg = toInt32(args[0]); + imp->overloadedMethod(intArg); + return v8::Handle<v8::Value>(); +} + +static v8::Handle<v8::Value> overloadedMethodCallback(const v8::Arguments& args) +{ + INC_STATS("DOM.TestObj.overloadedMethod"); + if ((args.Length() == 2 && (args[0]->IsNull() || V8TestObj::HasInstance(args[0])) && (args[1]->IsNull() || args[1]->IsUndefined() || args[1]->IsString() || args[1]->IsObject()))) + return overloadedMethod1Callback(args); + if ((args.Length() == 1 && (args[0]->IsNull() || V8TestObj::HasInstance(args[0]))) || (args.Length() == 2 && (args[0]->IsNull() || V8TestObj::HasInstance(args[0])))) + return overloadedMethod2Callback(args); + if ((args.Length() == 1 && (args[0]->IsNull() || args[0]->IsUndefined() || args[0]->IsString() || args[0]->IsObject()))) + return overloadedMethod3Callback(args); + if (args.Length() == 1) + return overloadedMethod4Callback(args); + V8Proxy::setDOMException(SYNTAX_ERR); + return notHandledByInterceptor(); +} + +} // namespace TestObjInternal + +static const BatchedAttribute TestObjAttrs[] = { + // Attribute 'readOnlyIntAttr' (Type: 'readonly attribute' ExtAttr: '') + {"readOnlyIntAttr", TestObjInternal::readOnlyIntAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, + // Attribute 'readOnlyStringAttr' (Type: 'readonly attribute' ExtAttr: '') + {"readOnlyStringAttr", TestObjInternal::readOnlyStringAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, + // Attribute 'readOnlyTestObjAttr' (Type: 'readonly attribute' ExtAttr: '') + {"readOnlyTestObjAttr", TestObjInternal::readOnlyTestObjAttrAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, + // Attribute 'intAttr' (Type: 'attribute' ExtAttr: '') + {"intAttr", TestObjInternal::intAttrAttrGetter, TestObjInternal::intAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, + // Attribute 'stringAttr' (Type: 'attribute' ExtAttr: '') + {"stringAttr", TestObjInternal::stringAttrAttrGetter, TestObjInternal::stringAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, + // Attribute 'testObjAttr' (Type: 'attribute' ExtAttr: '') + {"testObjAttr", TestObjInternal::testObjAttrAttrGetter, TestObjInternal::testObjAttrAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, + // Attribute 'attrWithException' (Type: 'attribute' ExtAttr: '') + {"attrWithException", TestObjInternal::attrWithExceptionAttrGetter, TestObjInternal::attrWithExceptionAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, + // Attribute 'attrWithSetterException' (Type: 'attribute' ExtAttr: '') + {"attrWithSetterException", TestObjInternal::attrWithSetterExceptionAttrGetter, TestObjInternal::attrWithSetterExceptionAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, + // Attribute 'attrWithGetterException' (Type: 'attribute' ExtAttr: '') + {"attrWithGetterException", TestObjInternal::attrWithGetterExceptionAttrGetter, TestObjInternal::attrWithGetterExceptionAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, + // Attribute 'customAttr' (Type: 'attribute' ExtAttr: 'Custom') + {"customAttr", V8TestObj::customAttrAccessorGetter, V8TestObj::customAttrAccessorSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, +}; +static const BatchedCallback TestObjCallbacks[] = { + {"voidMethod", TestObjInternal::voidMethodCallback}, + {"intMethod", TestObjInternal::intMethodCallback}, + {"objMethod", TestObjInternal::objMethodCallback}, + {"methodWithException", TestObjInternal::methodWithExceptionCallback}, + {"customMethod", V8TestObj::customMethodCallback}, + {"customMethodWithArgs", V8TestObj::customMethodWithArgsCallback}, + {"methodWithOptionalArg", TestObjInternal::methodWithOptionalArgCallback}, + {"methodWithNonOptionalArgAndOptionalArg", TestObjInternal::methodWithNonOptionalArgAndOptionalArgCallback}, + {"methodWithNonOptionalArgAndTwoOptionalArgs", TestObjInternal::methodWithNonOptionalArgAndTwoOptionalArgsCallback}, + {"overloadedMethod", TestObjInternal::overloadedMethodCallback}, +}; +static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestObjTemplate(v8::Persistent<v8::FunctionTemplate> desc) +{ + v8::Local<v8::Signature> defaultSignature = configureTemplate(desc, "TestObj", v8::Persistent<v8::FunctionTemplate>(), V8TestObj::internalFieldCount, + TestObjAttrs, sizeof(TestObjAttrs) / sizeof(*TestObjAttrs), + TestObjCallbacks, sizeof(TestObjCallbacks) / sizeof(*TestObjCallbacks)); + v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate(); + + + // Custom Signature 'voidMethodWithArgs' + const int voidMethodWithArgsArgc = 3; + v8::Handle<v8::FunctionTemplate> voidMethodWithArgsArgv[voidMethodWithArgsArgc] = { v8::Handle<v8::FunctionTemplate>(), v8::Handle<v8::FunctionTemplate>(), V8TestObj::GetRawTemplate() }; + v8::Handle<v8::Signature> voidMethodWithArgsSignature = v8::Signature::New(desc, voidMethodWithArgsArgc, voidMethodWithArgsArgv); + proto->Set(v8::String::New("voidMethodWithArgs"), v8::FunctionTemplate::New(TestObjInternal::voidMethodWithArgsCallback, v8::Handle<v8::Value>(), voidMethodWithArgsSignature)); + + // Custom Signature 'intMethodWithArgs' + const int intMethodWithArgsArgc = 3; + v8::Handle<v8::FunctionTemplate> intMethodWithArgsArgv[intMethodWithArgsArgc] = { v8::Handle<v8::FunctionTemplate>(), v8::Handle<v8::FunctionTemplate>(), V8TestObj::GetRawTemplate() }; + v8::Handle<v8::Signature> intMethodWithArgsSignature = v8::Signature::New(desc, intMethodWithArgsArgc, intMethodWithArgsArgv); + proto->Set(v8::String::New("intMethodWithArgs"), v8::FunctionTemplate::New(TestObjInternal::intMethodWithArgsCallback, v8::Handle<v8::Value>(), intMethodWithArgsSignature)); + + // Custom Signature 'objMethodWithArgs' + const int objMethodWithArgsArgc = 3; + v8::Handle<v8::FunctionTemplate> objMethodWithArgsArgv[objMethodWithArgsArgc] = { v8::Handle<v8::FunctionTemplate>(), v8::Handle<v8::FunctionTemplate>(), V8TestObj::GetRawTemplate() }; + v8::Handle<v8::Signature> objMethodWithArgsSignature = v8::Signature::New(desc, objMethodWithArgsArgc, objMethodWithArgsArgv); + proto->Set(v8::String::New("objMethodWithArgs"), v8::FunctionTemplate::New(TestObjInternal::objMethodWithArgsCallback, v8::Handle<v8::Value>(), objMethodWithArgsSignature)); + + // Custom toString template + desc->Set(getToStringName(), getToStringTemplate()); + return desc; +} + +v8::Persistent<v8::FunctionTemplate> V8TestObj::GetRawTemplate() +{ + static v8::Persistent<v8::FunctionTemplate> V8TestObjRawCache = createRawTemplate(); + return V8TestObjRawCache; +} + +v8::Persistent<v8::FunctionTemplate> V8TestObj::GetTemplate() +{ + static v8::Persistent<v8::FunctionTemplate> V8TestObjCache = ConfigureV8TestObjTemplate(GetRawTemplate()); + 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> wrapper; + V8Proxy* proxy = 0; + wrapper = getDOMObjectMap().get(impl); + if (!wrapper.IsEmpty()) + return wrapper; + wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl); + if (wrapper.IsEmpty()) + return wrapper; + + impl->ref(); + getDOMObjectMap().set(impl, v8::Persistent<v8::Object>::New(wrapper)); + 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(); +} + +} // namespace WebCore diff --git a/WebCore/bindings/v8/test/V8TestObj.h b/WebCore/bindings/v8/test/V8TestObj.h new file mode 100644 index 0000000..5d6770a --- /dev/null +++ b/WebCore/bindings/v8/test/V8TestObj.h @@ -0,0 +1,53 @@ +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8TestObj_h +#define V8TestObj_h + +#include "StringHash.h" +#include "TestObj.h" +#include "WrapperTypeInfo.h" +#include <v8.h> +#include <wtf/HashMap.h> + +namespace WebCore { + +class V8TestObj { + +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 void derefObject(void*); + static WrapperTypeInfo info; + static v8::Handle<v8::Value> customMethodCallback(const v8::Arguments&); + static v8::Handle<v8::Value> customMethodWithArgsCallback(const v8::Arguments&); + 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; +}; + +v8::Handle<v8::Value> toV8(TestObj*); +v8::Handle<v8::Value> toV8(PassRefPtr<TestObj >); +} + +#endif // V8TestObj_h diff --git a/WebCore/bindings/v8/test/run_tests.py b/WebCore/bindings/v8/test/run_tests.py new file mode 100644 index 0000000..e27d559 --- /dev/null +++ b/WebCore/bindings/v8/test/run_tests.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +# +# Copyright (C) 2010 Google Inc. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +# This script generates h and cpp file for TestObj.idl using the V8 code +# generator. Please execute the script whenever changes are made to +# CodeGeneratorV8.pm, and submit the changes in V8TestObj.h/cpp in the same +# patch. This makes it easier to track and review changes in generated code. +# To execute, invoke: 'python run_tests.py' + +import os +import sys + + +def test(idlFilePath): + cmd = ['perl', '-w', + '-I../../scripts', + '../../scripts/generate-bindings.pl', + # idl include directories (path relative to generate-bindings.pl) + '--include .', + # place holder for defines (generate-bindings.pl requires it) + '--defines xxx', + '--generator V8', + '--outputDir .', + idlFilePath] + os.system(' '.join(cmd)) + + +def main(argv): + scriptDir = os.path.dirname(__file__) + os.chdir(scriptDir) + test('TestObj.idl') + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) |