V8TestNamedConstructor.cpp [plain text]
#include "config.h"
#include "V8TestNamedConstructor.h"
#include "ExceptionCode.h"
#include "RuntimeEnabledFeatures.h"
#include "V8Binding.h"
#include "V8BindingMacros.h"
#include "V8BindingState.h"
#include "V8DOMWrapper.h"
#include "V8IsolatedContext.h"
#include "V8Proxy.h"
#include <wtf/UnusedParam.h>
namespace WebCore {
WrapperTypeInfo V8TestNamedConstructor::info = { V8TestNamedConstructor::GetTemplate, V8TestNamedConstructor::derefObject, V8TestNamedConstructor::toActiveDOMObject, 0 };
namespace TestNamedConstructorV8Internal {
template <typename T> void V8_USE(T) { }
}
WrapperTypeInfo V8TestNamedConstructorConstructor::info = { V8TestNamedConstructorConstructor::GetTemplate, V8TestNamedConstructor::derefObject, V8TestNamedConstructor::toActiveDOMObject, 0 };
static v8::Handle<v8::Value> V8TestNamedConstructorConstructorCallback(const v8::Arguments& args)
{
INC_STATS("DOM.TestNamedConstructor.Constructor");
if (!args.IsConstructCall())
return throwError("DOM object constructor cannot be called as a function.", V8Proxy::TypeError);
if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
return args.Holder();
Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
if (!frame)
return throwError("TestNamedConstructor constructor associated frame is unavailable", V8Proxy::ReferenceError);
Document* document = frame->document();
toV8(document, args.GetIsolate());
if (args.Length() < 1)
return V8Proxy::throwNotEnoughArgumentsError();
ExceptionCode ec = 0;
STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str1, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str2, MAYBE_MISSING_PARAMETER(args, 1, DefaultIsUndefined));
STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str3, MAYBE_MISSING_PARAMETER(args, 2, DefaultIsNullString));
RefPtr<TestNamedConstructor> impl = TestNamedConstructor::createForJSConstructor(document, str1, str2, str3, ec);
v8::Handle<v8::Object> wrapper = args.Holder();
if (ec)
goto fail;
V8DOMWrapper::setDOMWrapper(wrapper, &V8TestNamedConstructorConstructor::info, impl.get());
V8DOMWrapper::setJSWrapperForActiveDOMObject(impl.release(), v8::Persistent<v8::Object>::New(wrapper), args.GetIsolate());
return args.Holder();
fail:
return throwError(ec);
}
v8::Persistent<v8::FunctionTemplate> V8TestNamedConstructorConstructor::GetTemplate()
{
static v8::Persistent<v8::FunctionTemplate> cachedTemplate;
if (!cachedTemplate.IsEmpty())
return cachedTemplate;
v8::HandleScope scope;
v8::Local<v8::FunctionTemplate> result = v8::FunctionTemplate::New(V8TestNamedConstructorConstructorCallback);
v8::Local<v8::ObjectTemplate> instance = result->InstanceTemplate();
instance->SetInternalFieldCount(V8TestNamedConstructor::internalFieldCount);
result->SetClassName(v8::String::New("TestNamedConstructor"));
result->Inherit(V8TestNamedConstructor::GetTemplate());
cachedTemplate = v8::Persistent<v8::FunctionTemplate>::New(result);
return cachedTemplate;
}
static v8::Persistent<v8::FunctionTemplate> ConfigureV8TestNamedConstructorTemplate(v8::Persistent<v8::FunctionTemplate> desc)
{
desc->ReadOnlyPrototype();
v8::Local<v8::Signature> defaultSignature;
defaultSignature = configureTemplate(desc, "TestNamedConstructor", v8::Persistent<v8::FunctionTemplate>(), V8TestNamedConstructor::internalFieldCount,
0, 0,
0, 0);
UNUSED_PARAM(defaultSignature);
desc->Set(getToStringName(), getToStringTemplate());
return desc;
}
v8::Persistent<v8::FunctionTemplate> V8TestNamedConstructor::GetRawTemplate()
{
V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
V8BindingPerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info);
if (result != data->rawTemplateMap().end())
return result->second;
v8::HandleScope handleScope;
v8::Persistent<v8::FunctionTemplate> templ = createRawTemplate();
data->rawTemplateMap().add(&info, templ);
return templ;
}
v8::Persistent<v8::FunctionTemplate> V8TestNamedConstructor::GetTemplate()
{
V8BindingPerIsolateData* data = V8BindingPerIsolateData::current();
V8BindingPerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info);
if (result != data->templateMap().end())
return result->second;
v8::HandleScope handleScope;
v8::Persistent<v8::FunctionTemplate> templ =
ConfigureV8TestNamedConstructorTemplate(GetRawTemplate());
data->templateMap().add(&info, templ);
return templ;
}
bool V8TestNamedConstructor::HasInstance(v8::Handle<v8::Value> value)
{
return GetRawTemplate()->HasInstance(value);
}
ActiveDOMObject* V8TestNamedConstructor::toActiveDOMObject(v8::Handle<v8::Object> object)
{
return toNative(object);
}
v8::Handle<v8::Object> V8TestNamedConstructor::wrapSlow(PassRefPtr<TestNamedConstructor> impl, v8::Isolate* isolate)
{
v8::Handle<v8::Object> wrapper;
V8Proxy* proxy = 0;
wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl.get());
if (UNLIKELY(wrapper.IsEmpty()))
return wrapper;
v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(wrapper);
if (!hasDependentLifetime)
wrapperHandle.MarkIndependent();
V8DOMWrapper::setJSWrapperForActiveDOMObject(impl, wrapperHandle, isolate);
return wrapper;
}
void V8TestNamedConstructor::derefObject(void* object)
{
static_cast<TestNamedConstructor*>(object)->deref();
}
}