void ImageWrapper::NewImage( const v8::FunctionCallbackInfo< v8::Value >& args) { v8::Isolate* isolate = args.GetIsolate(); v8::HandleScope handleScope( isolate); if(!args.IsConstructCall()) { DALI_SCRIPT_EXCEPTION( isolate, "Image constructor called without 'new'"); return; } // find out the callee function name...e.g. BufferImage, ResourceImage v8::Local<v8::Function> callee = args.Callee(); v8::Local<v8::Value> v8String = callee->GetName(); std::string typeName = V8Utils::v8StringToStdString( v8String ); ImageType imageType = GetImageType( typeName ); if( imageType == UNKNOWN_IMAGE_TYPE ) { DALI_SCRIPT_EXCEPTION( isolate, "unknown image type"); return; } Image image = (ImageApiLookup[imageType].constructor)( args ); if( ! image ) { // a v8 exception will have been thrown by the constructor return; } v8::Local<v8::Object> localObject = WrapImage( isolate, image, imageType ); args.GetReturnValue().Set( localObject ); }
void frameWait(const v8::FunctionCallbackInfo<v8::Value>& args) { Interface::frameWait(); Local<External> shapeManagerExternal = Local<External>::Cast(args.Callee()->Get(String::NewFromUtf8(Isolate::GetCurrent(), shapeManagerStr.c_str()))); ShapeManager2d* shapeManager = static_cast<ShapeManager2d*>(shapeManagerExternal->Value()); UDPsocket socket = SDLNet_UDP_Open(0); // socket for writing. std::stringstream sstream; bostream out(sstream); out << *shapeManager; std::string str = sstream.str(); UDPpacket* packet = SDLNet_AllocPacket(str.size()); if(!packet) { std::cerr << "SDLNet_AllocPacket: " << SDLNet_GetError() << std::endl; // perhaps do something else since you can't make this packet } else { packet->len = str.size(); memcpy(packet->data, str.c_str(), str.size()); SDLNet_ResolveHost(&packet->address, "127.0.0.1", 54321); SDLNet_UDP_Send(socket, -1, packet); SDLNet_FreePacket(packet); } SDLNet_UDP_Close(socket); args.GetReturnValue().Set(Boolean::New(Isolate::GetCurrent(), true)); }
void V8PerIsolateData::constructorOfToString(const v8::FunctionCallbackInfo<v8::Value>& info) { // The DOM constructors' toString functions grab the current toString // for Functions by taking the toString function of itself and then // calling it with the constructor as its receiver. This means that // changes to the Function prototype chain or toString function are // reflected when printing DOM constructors. The only wart is that // changes to a DOM constructor's toString's toString will cause the // toString of the DOM constructor itself to change. This is extremely // obscure and unlikely to be a problem. v8::Handle<v8::Value> value = info.Callee()->Get(v8::String::NewSymbol("toString")); if (!value->IsFunction()) { v8SetReturnValue(info, v8::String::Empty(info.GetIsolate())); return; } v8SetReturnValue(info, V8ScriptRunner::callInternalFunction(v8::Handle<v8::Function>::Cast(value), info.This(), 0, 0, v8::Isolate::GetCurrent())); }
void makeLine(const v8::FunctionCallbackInfo<v8::Value>& args) { if(args.Length() != 4) { args.GetReturnValue().Set(Boolean::New(Isolate::GetCurrent(), false)); return; } Local<External> shapeManagerExternal = Local<External>::Cast(args.Callee()->Get(String::NewFromUtf8(Isolate::GetCurrent(), shapeManagerStr.c_str()))); ShapeManager2d* shapeManager = static_cast<ShapeManager2d*>(shapeManagerExternal->Value()); Point2d p1{args[0]->NumberValue(), args[1]->NumberValue()}; Point2d p2{args[2]->NumberValue(), args[3]->NumberValue()}; Local<Object> obj = initShape()->NewInstance(); unsigned int shape = shapeManager->makeLine(p1, p2); obj->SetInternalField(0, shapeManagerExternal); obj->SetInternalField(1, Integer::NewFromUnsigned(Isolate::GetCurrent(), shape)); args.GetReturnValue().Set(obj); }
static void constructorOfToString(const v8::FunctionCallbackInfo<v8::Value>& info) { // The DOM constructors' toString functions grab the current toString // for Functions by taking the toString function of itself and then // calling it with the constructor as its receiver. This means that // changes to the Function prototype chain or toString function are // reflected when printing DOM constructors. The only wart is that // changes to a DOM constructor's toString's toString will cause the // toString of the DOM constructor itself to change. This is extremely // obscure and unlikely to be a problem. v8::Isolate* isolate = info.GetIsolate(); v8::Local<v8::Value> value; if (!info.Callee()->Get(isolate->GetCurrentContext(), v8AtomicString(isolate, "toString")).ToLocal(&value) || !value->IsFunction()) { v8SetReturnValue(info, v8::String::Empty(isolate)); return; } v8::Local<v8::Value> result; if (V8ScriptRunner::callInternalFunction(v8::Local<v8::Function>::Cast(value), info.This(), 0, 0, isolate).ToLocal(&result)) v8SetReturnValue(info, result); }
static void constructCustomElement(const v8::FunctionCallbackInfo<v8::Value>& info) { v8::Isolate* isolate = info.GetIsolate(); if (!info.IsConstructCall()) { throwTypeError("DOM object constructor cannot be called as a function.", isolate); return; } if (info.Length() > 0) { throwTypeError("This constructor should be called without arguments.", isolate); return; } Document* document = V8Document::toNative(V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Callee(), V8HiddenValue::customElementDocument(isolate)).As<v8::Object>()); TOSTRING_VOID(V8StringResource<>, namespaceURI, V8HiddenValue::getHiddenValue(isolate, info.Callee(), V8HiddenValue::customElementNamespaceURI(isolate))); TOSTRING_VOID(V8StringResource<>, tagName, V8HiddenValue::getHiddenValue(isolate, info.Callee(), V8HiddenValue::customElementTagName(isolate))); v8::Handle<v8::Value> maybeType = V8HiddenValue::getHiddenValue(info.GetIsolate(), info.Callee(), V8HiddenValue::customElementType(isolate)); TOSTRING_VOID(V8StringResource<>, type, maybeType); ExceptionState exceptionState(ExceptionState::ConstructionContext, "CustomElement", info.Holder(), info.GetIsolate()); CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; RefPtrWillBeRawPtr<Element> element = document->createElementNS(namespaceURI, tagName, maybeType->IsNull() ? nullAtom : type, exceptionState); if (exceptionState.throwIfNeeded()) return; #if ENABLE(OILPAN) // FIXME: Oilpan: We don't have RawPtr<Eement> version of // v8SetReturnValueFast until Node.idl has WillBeGarbageCollected. v8SetReturnValueFast(info, element.get(), document); #else v8SetReturnValueFast(info, element.release(), document); #endif }