Exemplo n.º 1
0
void
JavascriptEngineV8::constructSpatialReferenceCallback(const v8::FunctionCallbackInfo<v8::Value> &info)
{
  if (!info.IsConstructCall())
  {
    v8::ThrowException(v8::String::New("Cannot call constructor as function"));
    return;
  }

	v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
 
  osgEarth::SpatialReference* srs;
  if (info.Length() == 1 && info[0]->IsString())
  {
    v8::String::Utf8Value utf8_value(info[0]->ToString());
    std::string init(*utf8_value);
    srs = osgEarth::SpatialReference::create(init);
  }

  if (!srs)
  {
    v8::ThrowException(v8::String::New("Unsupported arguments in constructor call"));
    return;
  }

  info.GetReturnValue().Set(JSSpatialReference::WrapSpatialReference(v8::Isolate::GetCurrent(), srs, true));
}
static void V8TestInterfaceNamedConstructor2ConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    if (!info.IsConstructCall()) {
        V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::constructorNotCallableAsFunction("Audio"));
        return;
    }

    if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
        v8SetReturnValue(info, info.Holder());
        return;
    }
    if (UNLIKELY(info.Length() < 1)) {
        V8ThrowException::throwException(createMinimumArityTypeErrorForConstructor(info.GetIsolate(), "TestInterfaceNamedConstructor2", 1, info.Length()), info.GetIsolate());
        return;
    }
    V8StringResource<> stringArg;
    {
        stringArg = info[0];
        if (!stringArg.prepare())
            return;
    }
    RefPtr<TestInterfaceNamedConstructor2> impl = TestInterfaceNamedConstructor2::createForJSConstructor(stringArg);
    v8::Local<v8::Object> wrapper = info.Holder();
    wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceNamedConstructor2Constructor::wrapperTypeInfo, wrapper);
    v8SetReturnValue(info, wrapper);
}
Exemplo n.º 3
0
void
JavascriptEngineV8::constructBoundsCallback(const v8::FunctionCallbackInfo<v8::Value> &info)
{
  if (!info.IsConstructCall())
  {
    v8::ThrowException(v8::String::New("Cannot call constructor as function"));
    return;
  }
 
	v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
 
  osgEarth::Bounds* bounds;
  //if (info.Length() == 0)
  //  bounds = new osgEarth::Bounds();
  //else
  if (info.Length() == 4)
    bounds = new osgEarth::Bounds(info[0]->NumberValue(), info[1]->NumberValue(), info[2]->NumberValue(), info[3]->NumberValue());

  if (!bounds)
  {
    v8::ThrowException(v8::String::New("Unsupported arguments in constructor call"));
    return;
  }

  info.GetReturnValue().Set(JSBounds::WrapBounds(v8::Isolate::GetCurrent(), bounds, true));
}
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;
    v8SetReturnValueFast(info, element.release(), document);
}
void npObjectInvokeDefaultHandler(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    if (args.IsConstructCall()) {
        npObjectInvokeImpl(args, InvokeConstruct);
        return;
    }

    npObjectInvokeImpl(args, InvokeDefault);
}
Exemplo n.º 6
0
 static
 void
 call(v8::FunctionCallbackInfo<v8::Value> const& args) {
     std::cout << "ctor called" << std::endl;
     if ( ! args.IsConstructCall()) {
         js_error("constructor called without 'new'");
         //throw_error_already_set();
         return; // XXX better throw...
     }
 }
Exemplo n.º 7
0
void V8HTMLElement::HTMLConstructor(
    const v8::FunctionCallbackInfo<v8::Value>& info) {
  DCHECK(info.IsConstructCall());

  v8::Isolate* isolate = info.GetIsolate();
  ScriptState* scriptState = ScriptState::current(isolate);

  if (!RuntimeEnabledFeatures::customElementsV1Enabled() ||
      !scriptState->world().isMainWorld()) {
    V8ThrowException::throwTypeError(info.GetIsolate(), "Illegal constructor");
    return;
  }

  LocalDOMWindow* window = scriptState->domWindow();
  ScriptCustomElementDefinition* definition =
      ScriptCustomElementDefinition::forConstructor(
          scriptState, window->customElements(), info.NewTarget());
  if (!definition) {
    V8ThrowException::throwTypeError(isolate, "Illegal constructor");
    return;
  }

  ExceptionState exceptionState(ExceptionState::ConstructionContext,
                                "HTMLElement", info.Holder(), isolate);

  Element* element;
  if (definition->constructionStack().isEmpty()) {
    // This is an element being created with 'new' from script
    element = definition->createElementForConstructor(*window->document());
  } else {
    element = definition->constructionStack().last();
    if (element) {
      // This is an element being upgraded that has called super
      definition->constructionStack().last().clear();
    } else {
      // During upgrade an element has invoked the same constructor
      // before calling 'super' and that invocation has poached the
      // element.
      exceptionState.throwDOMException(InvalidStateError,
                                       "this instance is already constructed");
      return;
    }
  }
  const WrapperTypeInfo* wrapperType = element->wrapperTypeInfo();
  v8::Local<v8::Object> wrapper = V8DOMWrapper::associateObjectWithWrapper(
      isolate, element, wrapperType, info.Holder());
  // If the element had a wrapper, we now update and return that
  // instead.
  v8SetReturnValue(info, wrapper);

  wrapper->SetPrototype(scriptState->context(), definition->prototype())
      .ToChecked();
}
void V8TestInterfaceEventInitConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    if (!info.IsConstructCall()) {
        V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceEventInitConstructor"));
        return;
    }

    if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
        v8SetReturnValue(info, info.Holder());
        return;
    }

    TestInterfaceEventInitConstructorV8Internal::constructor(info);
}
static void V8TestInterfaceConstructorConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    if (!info.IsConstructCall()) {
        V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::constructorNotCallableAsFunction("Audio"));
        return;
    }

    if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
        v8SetReturnValue(info, info.Holder());
        return;
    }
    ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestInterfaceConstructor", info.Holder(), info.GetIsolate());
    if (UNLIKELY(info.Length() < 1)) {
        setMinimumArityTypeError(exceptionState, 1, info.Length());
        exceptionState.throwIfNeeded();
        return;
    }
    V8StringResource<> arg;
    V8StringResource<> optArg;
    {
        TOSTRING_VOID_INTERNAL(arg, info[0]);
        if (UNLIKELY(info.Length() <= 1)) {
            ScriptState* scriptState = ScriptState::current(info.GetIsolate());
            ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
            Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
            RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::createForJSConstructor(scriptState, executionContext, document, arg, exceptionState);
            if (exceptionState.hadException()) {
                exceptionState.throwIfNeeded();
                return;
            }
            v8::Local<v8::Object> wrapper = info.Holder();
            impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceConstructorConstructor::wrapperTypeInfo, wrapper);
            v8SetReturnValue(info, wrapper);
            return;
        }
        TOSTRING_VOID_INTERNAL(optArg, info[1]);
    }
    ScriptState* scriptState = ScriptState::current(info.GetIsolate());
    ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate());
    Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    RefPtr<TestInterfaceConstructor> impl = TestInterfaceConstructor::createForJSConstructor(scriptState, executionContext, document, arg, optArg, exceptionState);
    if (exceptionState.hadException()) {
        exceptionState.throwIfNeeded();
        return;
    }
    v8::Local<v8::Object> wrapper = info.Holder();
    impl->associateWithWrapper(info.GetIsolate(), &V8TestInterfaceConstructorConstructor::wrapperTypeInfo, wrapper);
    v8SetReturnValue(info, wrapper);
}
void V8TestInterfaceCustomConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
    if (!info.IsConstructCall()) {
        throwTypeError(ExceptionMessages::failedToConstruct("TestInterfaceCustomConstructor", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), info.GetIsolate());
        return;
    }

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
        v8SetReturnValue(info, info.Holder());
        return;
    }

    V8TestInterfaceCustomConstructor::constructorCustom(info);
}
Exemplo n.º 11
0
void BuilderWrapper::NewBuilder( const v8::FunctionCallbackInfo< v8::Value >& args)
{
  v8::Isolate* isolate = args.GetIsolate();
  v8::HandleScope handleScope( isolate);

  if( !args.IsConstructCall() )
  {
    DALI_SCRIPT_EXCEPTION( isolate, "Builder constructor called without 'new'" );
    return;
  }

  Dali::Toolkit::Builder builder = BuilderApi::New( args );
  v8::Local<v8::Object> localObject = WrapBuilder( isolate, builder );
  args.GetReturnValue().Set( localObject );
}
void V8TestEventConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    TRACE_EVENT_SCOPED_SAMPLING_STATE("Blink", "DOMConstructor");
    if (!args.IsConstructCall()) {
        throwTypeError(ExceptionMessages::failedToConstruct("TestEventConstructor", "Please use the 'new' operator, this DOM object constructor cannot be called as a function."), args.GetIsolate());
        return;
    }

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
        args.GetReturnValue().Set(args.Holder());
        return;
    }

    TestEventConstructorV8Internal::constructor(args);
}
Exemplo n.º 13
0
void V8TestNode::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMConstructor");
    if (!info.IsConstructCall()) {
        V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("TestNode"), info.GetIsolate());
        return;
    }

    if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
        v8SetReturnValue(info, info.Holder());
        return;
    }

    TestNodeV8Internal::constructor(info);
}
Exemplo n.º 14
0
        static void newObject(const v8::FunctionCallbackInfo<v8::Value> & args)
        {
            if (args.IsConstructCall()) 
            {
                MethodMan call(args);

                if (args.Length() != 2) 
                {
                    call.throwException("Wrong number of arguments");
                    return;
                }

                // the first parameter is a Cluster object, let's unwrap it to get access to the underlying handle
                auto obj = call.checkedArgObject(0);

                if (!obj.second)
                {
                    call.throwException("Invalid parameter supplied to object");
                    return;
                } 

                auto str = call.checkedArgString(1);
                if (!str.second)
                {
                    call.throwException("Expected a string as an argument");
                    return;
                }

                v8::String::Utf8Value utf8str(str.first);

                // get access to the underlying handle
                Cluster * c = ObjectWrap::Unwrap<Cluster>(obj.first);

                Object * b = new Object(*c, *utf8str);

                b->Wrap(args.This());
                args.GetReturnValue().Set(args.This());
            } 
            else 
            {
                v8::Isolate* isolate = v8::Isolate::GetCurrent();
                // Invoked as plain function `MyObject(...)`, turn into construct call.
                const int argc = 2;
                v8::Local<v8::Value> argv[argc] = { args[0], args[1] };
                v8::Local<v8::Function> cons = v8::Local<v8::Function>::New(isolate, constructor);
                args.GetReturnValue().Set(cons->NewInstance(argc, argv));
            }      
        }
Exemplo n.º 15
0
void V8TestInterfaceConstructor::constructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    TRACE_EVENT_SCOPED_SAMPLING_STATE("blink", "DOMConstructor");
    UseCounter::countIfNotPrivateScript(info.GetIsolate(), callingExecutionContext(info.GetIsolate()), UseCounter::TestFeature);
    if (!info.IsConstructCall()) {
        V8ThrowException::throwTypeError(info.GetIsolate(), ExceptionMessages::constructorNotCallableAsFunction("TestInterfaceConstructor"));
        return;
    }

    if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
        v8SetReturnValue(info, info.Holder());
        return;
    }

    TestInterfaceConstructorV8Internal::constructor(info);
}
Exemplo n.º 16
0
        static void New(const v8::FunctionCallbackInfo<v8::Value>& args)
        {
            if (args.IsConstructCall()) 
            {
                MethodMan call(args);

                if (args.Length() != 1) 
                {
                    call.throwException("Wrong number of arguments");
                    return;
                }

                auto str = call.checkedArgString(0);
                if (!str.second)
                {
                    call.throwException("Expected a connection string as an argument");
                    return;
                }

                v8::String::Utf8Value utf8str(str.first);

                // create and open handle
                qdb_handle_t h = qdb_open_tcp();
                const qdb_error_t err = qdb_connect(h, *utf8str);
                if (err != qdb_e_ok)
                {
                    qdb_close(h);
                    call.throwException(qdb_error(err));;
                    return;    
                }

                // handle is now owned by the cluster object
                Cluster * cl = new Cluster(h);

                cl->Wrap(args.This());
                args.GetReturnValue().Set(args.This());
            } 
            else 
            {
                v8::Isolate* isolate = v8::Isolate::GetCurrent();
                // Invoked as plain function `MyObject(...)`, turn into construct call.
                const int argc = 1;
                v8::Local<v8::Value> argv[argc] = { args[0] };
                v8::Local<v8::Function> cons = v8::Local<v8::Function>::New(isolate, constructor);
                args.GetReturnValue().Set(cons->NewInstance(argc, argv));
            }
        }
static void V8TestInterfaceEventTargetConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    if (!info.IsConstructCall()) {
        V8ThrowException::throwTypeError(ExceptionMessages::constructorNotCallableAsFunction("Name"), info.GetIsolate());
        return;
    }

    if (ConstructorMode::current(info.GetIsolate()) == ConstructorMode::WrapExistingObject) {
        v8SetReturnValue(info, info.Holder());
        return;
    }
    Document& document = *toDocument(currentExecutionContext(info.GetIsolate()));
    RefPtrWillBeRawPtr<TestInterfaceEventTarget> impl = TestInterfaceEventTarget::createForJSConstructor(document);
    v8::Handle<v8::Object> wrapper = info.Holder();
    impl->associateWithWrapper(&V8TestInterfaceEventTargetConstructor::wrapperTypeInfo, wrapper, info.GetIsolate());
    v8SetReturnValue(info, wrapper);
}
Exemplo n.º 18
0
void ProcessWrap::New(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::HandleScope scope(isolate);

    if (args.IsConstructCall()) {
        // Invoked as constructor: `new MyObject(...)`
        ProcessWrap* obj = new ProcessWrap();
        obj->Wrap(args.This());
        args.GetReturnValue().Set(args.This());
    }
    else {
        // Invoked as plain function `DriverControlWrap(...)`, turn into construct call.
        v8::Local<v8::Function> cons = v8::Local<v8::Function>::New(isolate, constructor);
        args.GetReturnValue().Set(cons->NewInstance());
    }
}
Exemplo n.º 19
0
void MaterialWrapper::NewMaterial( const v8::FunctionCallbackInfo< v8::Value >& args)
{
  v8::Isolate* isolate = args.GetIsolate();
  v8::HandleScope handleScope( isolate);

  if(!args.IsConstructCall())
  {
      DALI_SCRIPT_EXCEPTION( isolate, "Material constructor called without 'new'");
      return;
  }
  Dali::Material material = MaterialApi::New( args );

  if(material)
  {
    v8::Local<v8::Object> localObject = WrapMaterial( isolate, material );
    args.GetReturnValue().Set( localObject );
  }
}
Exemplo n.º 20
0
void ShaderEffectWrapper::NewShaderEffect( const v8::FunctionCallbackInfo< v8::Value >& args)
{
  v8::Isolate* isolate = args.GetIsolate();
  v8::HandleScope handleScope( isolate);

  if(!args.IsConstructCall())
  {
      DALI_SCRIPT_EXCEPTION( isolate, "ShaderEffect constructor called without 'new'");
      return;
  }
  Dali::ShaderEffect shaderEffect = ShaderEffectApi::New( isolate, args );

  if(shaderEffect)
  {
    v8::Local<v8::Object> localObject = WrapShaderEffect( isolate, shaderEffect );
    args.GetReturnValue().Set( localObject );
  }
}
Exemplo n.º 21
0
    void JSZCluster::constructor(const v8::FunctionCallbackInfo<v8::Value> &info) {
        if (info.IsConstructCall()) {
            return;
        }
        Isolate *isolate = info.GetIsolate();
        try {
            JSZCluster *This = (JSZCluster *) (Local<External>::Cast(info.Data())->Value());
            checkConstructorValidArgument(isolate, info);
            ExtAddress extAddress = getExtAddressFromArg(info, 0);
            EndpointID endpointId(info[1].As<v8::Integer>()->Value());
            ClusterID clusterId(info[2].As<v8::Integer>()->Value());

            info.GetReturnValue().Set(This->createInstance(info.GetIsolate(), extAddress, endpointId, clusterId));
        } catch (std::exception &excp) {
            v8::Local<v8::String> errorMsg = v8::String::NewFromUtf8(isolate, excp.what());
            isolate->ThrowException(errorMsg);
        }
    }
static void constructCustomElement(
    const v8::FunctionCallbackInfo<v8::Value>& info) {
  v8::Isolate* isolate = info.GetIsolate();

  if (!info.IsConstructCall()) {
    V8ThrowException::throwTypeError(
        isolate, "DOM object constructor cannot be called as a function.");
    return;
  }

  if (info.Length() > 0) {
    V8ThrowException::throwTypeError(
        isolate, "This constructor should be called without arguments.");
    return;
  }

  ScriptState* scriptState = ScriptState::current(isolate);
  v8::Local<v8::Object> data = v8::Local<v8::Object>::Cast(info.Data());
  Document* document = V8Document::toImpl(
      V8HiddenValue::getHiddenValue(
          scriptState, data, V8HiddenValue::customElementDocument(isolate))
          .As<v8::Object>());
  TOSTRING_VOID(V8StringResource<>, namespaceURI,
                V8HiddenValue::getHiddenValue(
                    scriptState, data,
                    V8HiddenValue::customElementNamespaceURI(isolate)));
  TOSTRING_VOID(
      V8StringResource<>, tagName,
      V8HiddenValue::getHiddenValue(
          scriptState, data, V8HiddenValue::customElementTagName(isolate)));
  v8::Local<v8::Value> maybeType = V8HiddenValue::getHiddenValue(
      scriptState, data, V8HiddenValue::customElementType(isolate));
  TOSTRING_VOID(V8StringResource<>, type, maybeType);

  ExceptionState exceptionState(ExceptionState::ConstructionContext,
                                "CustomElement", info.Holder(),
                                info.GetIsolate());
  V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
  Element* element = document->createElementNS(
      namespaceURI, tagName, maybeType->IsNull() ? nullAtom : type,
      exceptionState);
  v8SetReturnValueFast(info, element, document);
}
Exemplo n.º 23
0
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args) {
      Isolate* isolate = args.GetIsolate();

      if (args.IsConstructCall()) {
        // Invoked as constructor: `new Polynomial(...)`
        double a = args[0]->IsUndefined() ? 0 : args[0]->NumberValue();
        double b = args[1]->IsUndefined() ? 0 : args[1]->NumberValue();
        double c = args[2]->IsUndefined() ? 0 : args[2]->NumberValue();
        WrappedPoly* obj = new WrappedPoly(a, b, c);
        obj->Wrap(args.This());
        args.GetReturnValue().Set(args.This());
      } else {
          
        // Invoked as plain function `Polynomial(...)`, turn into construct call.
        const int argc = 3;
        Local<Value> argv[argc] = { args[0] , args[1], args[2]};
        Local<Function> cons = Local<Function>::New(isolate, constructor);
        args.GetReturnValue().Set(cons->NewInstance(argc, argv));
      }
  }
Exemplo n.º 24
0
void MetadataNode::ExtendedClassConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
	try
	{
		SET_PROFILER_FRAME();

		assert(info.IsConstructCall());

		auto isolate = info.GetIsolate();
		auto thiz = info.This();
		auto extData = reinterpret_cast<ExtendedClassData*>(info.Data().As<External>()->Value());

		auto implementationObject = Local<Object>::New(isolate, *extData->implementationObject);

		const auto& extendName = extData->extendedName;

		SetInstanceMetadata(isolate, thiz, extData->node);
		thiz->SetInternalField(static_cast<int>(ObjectManager::MetadataNodeKeys::CallSuper), True(isolate));
		thiz->SetHiddenValue(ConvertToV8String("t::implObj"), implementationObject);

		ArgsWrapper argWrapper(info, ArgType::Class, Local<Object>());

		string fullClassName = extData->fullClassName;

		bool success = NativeScriptRuntime::RegisterInstance(thiz, fullClassName, argWrapper, implementationObject, false);
	}
	catch (NativeScriptException& e)
	{
		e.ReThrowToV8();
	}
	catch (std::exception e) {
		stringstream ss;
		ss << "Error: c++ exception: " << e.what() << endl;
		NativeScriptException nsEx(ss.str());
		nsEx.ReThrowToV8();
	}
	catch (...) {
		NativeScriptException nsEx(std::string("Error: c++ exception!"));
		nsEx.ReThrowToV8();
	}
}
Exemplo n.º 25
0
void TNodeJsFOut::New(const v8::FunctionCallbackInfo<v8::Value>& Args) {
	EAssertR(Args.IsConstructCall(), "TNodeJsFOut: not a constructor call (you forgot to use the new operator)");
	v8::Isolate* Isolate = v8::Isolate::GetCurrent();
    v8::EscapableHandleScope HandleScope(Isolate);
	// set hidden class id
	v8::Local<v8::Object> Instance = Args.This();
	v8::Handle<v8::String> key = v8::String::NewFromUtf8(Isolate, "class");
	v8::Handle<v8::String> value = v8::String::NewFromUtf8(Isolate, GetClassId().CStr());
	Instance->SetHiddenValue(key, value);		
	// empty constructor call just forwards the instance
	if (Args.Length() == 0) { Args.GetReturnValue().Set(Instance); return; }
	// parse arguments
	EAssertR(Args.Length() >= 1 && Args[0]->IsString(),
		"Expected file path.");
	TStr FNm(*v8::String::Utf8Value(Args[0]->ToString()));
	bool AppendP = Args.Length() >= 2 && Args[1]->IsBoolean() && Args[1]->BooleanValue();
	// Args.This() is an instance, wrap our C++ object
	TNodeJsFOut* Obj = new TNodeJsFOut(FNm, AppendP);
	Obj->Wrap(Instance);
	Args.GetReturnValue().Set(Instance);	
}
static void v8HTMLImageElementConstructorMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    if (!args.IsConstructCall()) {
        throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
        return;
    }

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject) {
        v8SetReturnValue(args, args.Holder());
        return;
    }

    Document* document = currentDocument();
    ASSERT(document);

    // Make sure the document is added to the DOM Node map. Otherwise, the HTMLImageElement instance
    // may end up being the only node in the map and get garbage-collected prematurely.
    // FIXME: The correct way to do this would be to make HTMLImageElement derive from
    // ActiveDOMObject and use its interface to keep its wrapper alive. Then we would
    // remove this code and the special case in isObservableThroughDOM.
    toV8(document, args.Holder(), args.GetIsolate());

    int width;
    int height;
    int* optionalWidth = 0;
    int* optionalHeight = 0;
    if (args.Length() > 0) {
        width = toInt32(args[0]);
        optionalWidth = &width;
    }
    if (args.Length() > 1) {
        height = toInt32(args[1]);
        optionalHeight = &height;
    }

    RefPtr<HTMLImageElement> image = HTMLImageElement::createForJSConstructor(*document, optionalWidth, optionalHeight);
    v8::Handle<v8::Object> wrapper = args.Holder();
    V8DOMWrapper::associateObjectWithWrapper<V8HTMLImageElement>(image.release(), &V8HTMLImageElementConstructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
    v8SetReturnValue(args, wrapper);
}
Exemplo n.º 27
0
      // Creates a new instance of this class
      static void Create (const v8::FunctionCallbackInfo<v8::Value>& args)
      {
         auto isolate = args.GetIsolate ();
         v8::HandleScope scope (isolate);

         if (args.IsConstructCall ())
         {
            // invoked as constructor: 'new Object(...)'
            auto module = new TDerivedLokiModule ();
            module->Wrap (args.This ());

            args.GetReturnValue ().Set (args.This ());
         }
         else
         {
            // invoked as a plain function 'Object(...)', turn into function call
            const int argc = 1;
            v8::Local<v8::Value> argv [argc] = {args [0]};
            auto ctor = v8::Local<v8::Function>::New (isolate, constructor);
            args.GetReturnValue ().Set (ctor->NewInstance (argc, argv));
         }
      }
Exemplo n.º 28
0
    void JSZAttribute::constructor(const v8::FunctionCallbackInfo<v8::Value> &info) {
        if (info.IsConstructCall()) {
            return;
        }
        Isolate *isolate = info.GetIsolate();
        try {
            validateParams(info);
            ExtAddress extAddress = getExtAddressFromArg(info);
            EndpointID endpointId(info[1].As<v8::Integer>()->Value());
            ClusterID clusterId(info[2].As<v8::Integer>()->Value());
            uint32_t attributeId = info[3].As<v8::Integer>()->Value();
            JSZAttribute *This = (JSZAttribute *) (Local<External>::Cast(info.Data())->Value());

            std::shared_ptr<ZCLAttribute> zclAttribute = This->getZCLAttribute(extAddress, endpointId, clusterId,
                                                                               attributeId);

            info.GetReturnValue().Set(This->createInstance(isolate, zclAttribute));
        } catch (std::exception &excp) {
            v8::Local<v8::String> errorMsg = v8::String::NewFromUtf8(isolate, excp.what());
            isolate->ThrowException(errorMsg);
        }
    }
Exemplo n.º 29
0
void JsVlcPlayer::jsCreate( const v8::FunctionCallbackInfo<v8::Value>& args )
{
    using namespace v8;

    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope( isolate );

    Local<Object> thisObject = args.Holder();
    if( args.IsConstructCall() ) {
        Local<Array> options;
        if( args.Length() == 1 && args[0]->IsArray() ) {
            options = Local<Array>::Cast( args[0] );
        }

        JsVlcPlayer* jsPlayer = new JsVlcPlayer( thisObject, options );
        args.GetReturnValue().Set( jsPlayer->handle() );
    } else {
        Local<Value> argv[] = { args[0] };
        Local<Function> constructor =
            Local<Function>::New( isolate, _jsConstructor );
        args.GetReturnValue().Set( constructor->NewInstance( sizeof( argv ) / sizeof( argv[0] ), argv ) );
    }
}
Exemplo n.º 30
0
void JsVlcVideo::jsCreate( const v8::FunctionCallbackInfo<v8::Value>& args )
{
    using namespace v8;

    Isolate* isolate = Isolate::GetCurrent();
    HandleScope scope( isolate );

    Local<Object> thisObject = args.Holder();
    if( args.IsConstructCall() && thisObject->InternalFieldCount() > 0 ) {
        JsVlcPlayer* jsPlayer =
            ObjectWrap::Unwrap<JsVlcPlayer>( Handle<Object>::Cast( args[0] ) );
        if( jsPlayer ) {
            JsVlcVideo* jsPlaylist = new JsVlcVideo( thisObject, jsPlayer );
            args.GetReturnValue().Set( thisObject );
        }
    } else {
        Local<Function> constructor =
            Local<Function>::New( isolate, _jsConstructor );
        Local<Value> argv[] = { args[0] };
        args.GetReturnValue().Set(
            constructor->NewInstance( sizeof( argv ) / sizeof( argv[0] ), argv ) );
    }
}