v8::Handle<v8::Value> V8Location::replaceAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { INC_STATS("DOM.Location.replace._get"); static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(V8Location::replaceCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); v8::Handle<v8::Object> holder = V8DOMWrapper::lookupDOMWrapper(V8Location::GetTemplate(), info.This()); if (holder.IsEmpty()) { // can only reach here by 'object.__proto__.func', and it should passed // domain security check already return privateTemplate->GetFunction(); } Location* imp = V8Location::toNative(holder); if (!V8BindingSecurity::canAccessFrame(V8BindingState::Only(), imp->frame(), false)) { static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(V8Location::replaceCallback, v8::Handle<v8::Value>(), v8::Signature::New(V8Location::GetRawTemplate()))); return sharedTemplate->GetFunction(); } return privateTemplate->GetFunction(); }
v8::Handle<v8::Value> V8Location::replaceAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { v8::Isolate* isolate = info.GetIsolate(); static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, v8::FunctionTemplate::New(V8Location::replaceCallback, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate)))); v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8Location::GetTemplate(isolate)); if (holder.IsEmpty()) { // can only reach here by 'object.__proto__.func', and it should passed // domain security check already return privateTemplate->GetFunction(); } Location* imp = V8Location::toNative(holder); if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError)) { static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(isolate, v8::FunctionTemplate::New(V8Location::replaceCallback, v8Undefined(), v8::Signature::New(V8Location::GetRawTemplate(isolate)))); return sharedTemplate->GetFunction(); } return privateTemplate->GetFunction(); }
static v8::Handle<v8::Value> postMessageAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) { static v8::Persistent<v8::FunctionTemplate> privateTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(TestActiveDOMObjectV8Internal::postMessageCallback, v8Undefined(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate()))); v8::Handle<v8::Object> holder = info.This()->FindInstanceInPrototypeChain(V8TestActiveDOMObject::GetTemplate()); if (holder.IsEmpty()) { // can only reach here by 'object.__proto__.func', and it should passed // domain security check already return privateTemplate->GetFunction(); } TestActiveDOMObject* imp = V8TestActiveDOMObject::toNative(holder); if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError)) { static v8::Persistent<v8::FunctionTemplate> sharedTemplate = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New(TestActiveDOMObjectV8Internal::postMessageCallback, v8Undefined(), v8::Signature::New(V8TestActiveDOMObject::GetRawTemplate()))); return sharedTemplate->GetFunction(); } v8::Local<v8::Value> hiddenValue = info.This()->GetHiddenValue(name); if (!hiddenValue.IsEmpty()) return hiddenValue; return privateTemplate->GetFunction(); }
static Handle<v8::Value> NewInstance(const v8::Arguments& args) { HandleScope scope; Local<Value> argv[1] = { Uint32::New(args[0]->ToUint32()->IntegerValue()) }; Local<Object> instance = Constructor->GetFunction()->NewInstance(1,argv); Float64Array* pThis = node::ObjectWrap::Unwrap<Float64Array>(instance); instance->SetIndexedPropertiesToExternalArrayData((void * )pThis->buffer.get(), v8::kExternalDoubleArray, (int)pThis->length); //pThis->setShape(shape); return scope.Close(instance); }
void XpcConnection::Init(v8::Handle<v8::Object> target) { v8::HandleScope scope; v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(XpcConnection::New); s_ct = v8::Persistent<v8::FunctionTemplate>::New(t); s_ct->InstanceTemplate()->SetInternalFieldCount(1); s_ct->SetClassName(v8::String::NewSymbol("XpcConnection")); NODE_SET_PROTOTYPE_METHOD(s_ct, "setup", XpcConnection::Setup); NODE_SET_PROTOTYPE_METHOD(s_ct, "sendMessage", XpcConnection::SendMessage); target->Set(v8::String::NewSymbol("XpcConnection"), s_ct->GetFunction()); }
v8::Local<v8::Object> createV8ObjectForNPObject(NPObject* object, NPObject* root) { static v8::Persistent<v8::FunctionTemplate> npObjectDesc; ASSERT(v8::Context::InContext()); // If this is a v8 object, just return it. if (object->_class == npScriptObjectClass) { V8NPObject* v8NPObject = reinterpret_cast<V8NPObject*>(object); return v8::Local<v8::Object>::New(v8NPObject->v8Object); } // If we've already wrapped this object, just return it. if (staticNPObjectMap.contains(object)) return v8::Local<v8::Object>::New(staticNPObjectMap.get(object)); // FIXME: we should create a Wrapper type as a subclass of JSObject. It has two internal fields, field 0 is the wrapped // pointer, and field 1 is the type. There should be an api function that returns unused type id. The same Wrapper type // can be used by DOM bindings. if (npObjectDesc.IsEmpty()) { npObjectDesc = v8::Persistent<v8::FunctionTemplate>::New(v8::FunctionTemplate::New()); npObjectDesc->InstanceTemplate()->SetInternalFieldCount(V8Custom::kNPObjectInternalFieldCount); npObjectDesc->InstanceTemplate()->SetNamedPropertyHandler(npObjectNamedPropertyGetter, npObjectNamedPropertySetter); npObjectDesc->InstanceTemplate()->SetIndexedPropertyHandler(npObjectIndexedPropertyGetter, npObjectIndexedPropertySetter); npObjectDesc->InstanceTemplate()->SetCallAsFunctionHandler(npObjectInvokeDefaultHandler); } v8::Handle<v8::Function> v8Function = npObjectDesc->GetFunction(); v8::Local<v8::Object> value = SafeAllocation::newInstance(v8Function); // If we were unable to allocate the instance, we avoid wrapping and registering the NP object. if (value.IsEmpty()) return value; wrapNPObject(value, object); // KJS retains the object as part of its wrapper (see Bindings::CInstance). _NPN_RetainObject(object); _NPN_RegisterObject(object, root); // Maintain a weak pointer for v8 so we can cleanup the object. v8::Persistent<v8::Object> weakRef = v8::Persistent<v8::Object>::New(value); staticNPObjectMap.set(object, weakRef); return value; }
static void Init(v8::Handle<v8::Object> target) { v8::HandleScope scope; v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(New); s_ct = v8::Persistent<v8::FunctionTemplate>::New(t); s_ct->InstanceTemplate()->SetInternalFieldCount(1); s_ct->SetClassName(v8::String::NewSymbol("NodeMidiOutput")); NODE_SET_PROTOTYPE_METHOD(s_ct, "getPortCount", GetPortCount); NODE_SET_PROTOTYPE_METHOD(s_ct, "getPortName", GetPortName); NODE_SET_PROTOTYPE_METHOD(s_ct, "openPort", OpenPort); NODE_SET_PROTOTYPE_METHOD(s_ct, "openVirtualPort", OpenVirtualPort); NODE_SET_PROTOTYPE_METHOD(s_ct, "closePort", ClosePort); NODE_SET_PROTOTYPE_METHOD(s_ct, "sendMessage", SendMessage); target->Set(v8::String::NewSymbol("output"), s_ct->GetFunction()); }