| Index: Source/bindings/v8/V8ScriptRunner.cpp
|
| diff --git a/Source/bindings/v8/V8ScriptRunner.cpp b/Source/bindings/v8/V8ScriptRunner.cpp
|
| index 515ee0df164b7422107b1156b5e83974e56be719..908f807d2bf1318dd76eafb1adf78592257e7b6b 100644
|
| --- a/Source/bindings/v8/V8ScriptRunner.cpp
|
| +++ b/Source/bindings/v8/V8ScriptRunner.cpp
|
| @@ -28,6 +28,7 @@
|
|
|
| #include "bindings/v8/V8Binding.h"
|
| #include "bindings/v8/V8GCController.h"
|
| +#include "bindings/v8/V8HiddenPropertyName.h"
|
| #include "bindings/v8/V8RecursionScope.h"
|
| #include "core/dom/ScriptExecutionContext.h"
|
| #include "core/loader/CachedMetadata.h"
|
| @@ -115,6 +116,54 @@ v8::Local<v8::Value> V8ScriptRunner::compileAndRunInternalScript(v8::Handle<v8::
|
| return result;
|
| }
|
|
|
| +v8::Local<v8::Function> V8ScriptRunner::blinkJSConstructor(const char* name, WrapperTypeInfo* typeInfo, const String& source, int argc, v8::Handle<v8::Value> argv[], v8::Handle<v8::Context> context, v8::Isolate* isolate)
|
| +{
|
| + v8::Local<v8::Object> global = isolate->GetCurrentContext()->Global();
|
| + V8PerContextData* perContextData = V8PerContextData::from(context);
|
| + if (!perContextData) {
|
| + String message = String(name) + " constructor is not found";
|
| + throwError(v8GeneralError, message.utf8().data(), isolate);
|
| + return v8::Local<v8::Function>();
|
| + }
|
| + v8::Local<v8::Value> wrapperConstructor = perContextData->constructorForType(typeInfo);
|
| + if (wrapperConstructor.IsEmpty() || !wrapperConstructor->IsObject()) {
|
| + String message = String(name) + " constructor is not found";
|
| + throwError(v8GeneralError, message.utf8().data(), isolate);
|
| + return v8::Local<v8::Function>();
|
| + }
|
| + v8::Local<v8::Value> value = wrapperConstructor.As<v8::Object>()->GetHiddenValue(V8HiddenPropertyName::constructor());
|
| + if (!value.IsEmpty() && value->IsFunction()) {
|
| + // Return the stored constructor.
|
| + return value.As<v8::Function>();
|
| + }
|
| +
|
| + value = V8ScriptRunner::compileAndRunInternalScript(v8String(source, isolate), isolate);
|
| + if (value.IsEmpty())
|
| + return v8::Local<v8::Function>();
|
| + if (!value->IsFunction()) {
|
| + String message = String(name) + " constructor implementation must be a function";
|
| + throwError(v8TypeError, message.utf8().data(), isolate);
|
| + return v8::Local<v8::Function>();
|
| + }
|
| +
|
| + v8::Local<v8::Function> impl = value.As<v8::Function>();
|
| + value = impl->Call(v8::Object::New(), argc, argv);
|
| + if (value.IsEmpty())
|
| + return v8::Local<v8::Function>();
|
| + if (!value->IsFunction()) {
|
| + String message = String(name) + " constructor must be a function";
|
| + throwError(v8TypeError, message.utf8().data(), isolate);
|
| + return v8::Local<v8::Function>();
|
| + }
|
| + bool result = wrapperConstructor.As<v8::Object>()->SetHiddenValue(V8HiddenPropertyName::constructor(), value);
|
| + if (!result) {
|
| + String message = String(name) + " constructor is not found";
|
| + throwError(v8GeneralError, message.utf8().data(), isolate);
|
| + return v8::Local<v8::Function>();
|
| + }
|
| + return value.As<v8::Function>();
|
| +}
|
| +
|
| static String functionInfo(const v8::Handle<v8::Function> function)
|
| {
|
| String resourceName = "undefined";
|
| @@ -198,4 +247,58 @@ v8::Local<v8::Object> V8ScriptRunner::instantiateObjectInDocument(v8::Handle<v8:
|
| return result;
|
| }
|
|
|
| +v8::Local<v8::Value> V8ScriptRunner::callUnwrappedMethod(const char* name, const v8::FunctionCallbackInfo<v8::Value>& args, v8::Handle<v8::Value> prototype)
|
| +{
|
| + Vector<v8::Handle<v8::Value> > arguments;
|
| + for (int i = 0; i < args.Length(); ++i)
|
| + arguments.append(args[i]);
|
| + return callUnwrappedMethod(name, args.This(), arguments.size(), arguments.data(), args.GetIsolate(), prototype);
|
| +}
|
| +
|
| +v8::Local<v8::Value> V8ScriptRunner::callUnwrappedMethod(const char* name, v8::Handle<v8::Object> thisObject,
|
| + int argc, v8::Handle<v8::Value> argv[], v8::Isolate* isolate, v8::Handle<v8::Value> prototype)
|
| +{
|
| + if (thisObject.IsEmpty()) {
|
| + String message = String("Cannot call method '") + name + "' of undefined";
|
| + throwError(v8TypeError, message.utf8().data(), isolate);
|
| + return v8::Local<v8::Value>();
|
| + }
|
| + v8::Handle<v8::Value> unwrapped = thisObject->GetInternalField(v8DOMWrapperObjectIndex);
|
| + if (unwrapped.IsEmpty() || !unwrapped->IsObject()) {
|
| + throwError(v8TypeError, "The wrapped this value is not an object", isolate);
|
| + return v8::Local<v8::Value>();
|
| + }
|
| +
|
| + if (prototype.IsEmpty() || !prototype->IsObject()) {
|
| + throwError(v8TypeError, "The prototype is not an object", isolate);
|
| + return v8::Local<v8::Value>();
|
| + }
|
| +
|
| + v8::Local<v8::Value> property = prototype.As<v8::Object>()->Get(v8::String::NewSymbol(name));
|
| + if (property.IsEmpty() || !property->IsFunction()) {
|
| + String message = String("Property '") + name + "' of the object is not a function";
|
| + throwError(v8TypeError, message.utf8().data(), isolate);
|
| + return v8::Local<v8::Value>();
|
| + }
|
| + return property.As<v8::Function>()->Call(unwrapped.As<v8::Object>(), argc, argv);
|
| +}
|
| +
|
| +v8::Local<v8::Value> V8ScriptRunner::callStaticMethod(const char* name, const v8::FunctionCallbackInfo<v8::Value>& args, v8::Handle<v8::Value> constructor)
|
| +{
|
| + if (constructor.IsEmpty() || !constructor->IsObject()) {
|
| + throwError(v8TypeError, "The constructor object is not found", args.GetIsolate());
|
| + return v8::Local<v8::Value>();
|
| + }
|
| + v8::Local<v8::Value> property = constructor.As<v8::Object>()->Get(v8::String::NewSymbol(name));
|
| + if (property.IsEmpty() || !property->IsFunction()) {
|
| + String message = String("Property '") + name + "' of the object is not a function";
|
| + throwError(v8TypeError, message.utf8().data(), args.GetIsolate());
|
| + return v8::Local<v8::Value>();
|
| + }
|
| + Vector<v8::Handle<v8::Value> > arguments;
|
| + for (int i = 0; i < args.Length(); ++i)
|
| + arguments.append(args[i]);
|
| + return property.As<v8::Function>()->Call(args.This(), arguments.size(), arguments.data());
|
| +}
|
| +
|
| } // namespace WebCore
|
|
|