Ejemplo n.º 1
0
v8::Handle<v8::Value> V8WebKitMutationObserver::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.WebKitMutationObserver.Constructor");

    if (!args.IsConstructCall())
        return V8Proxy::throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    if (args.Length() < 1)
        return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());

    v8::Local<v8::Value> arg = args[0];
    if (!arg->IsObject())
        return throwError(TYPE_MISMATCH_ERR, args.GetIsolate());

    ScriptExecutionContext* context = getScriptExecutionContext();
    if (!context)
        return V8Proxy::throwError(V8Proxy::ReferenceError, "WebKitMutationObserver constructor's associated frame unavailable", args.GetIsolate());

    RefPtr<MutationCallback> callback = V8MutationCallback::create(arg, context);
    RefPtr<WebKitMutationObserver> observer = WebKitMutationObserver::create(callback.release());

    V8DOMWrapper::setDOMWrapper(args.Holder(), &info, observer.get());
    V8DOMWrapper::setJSWrapperForDOMObject(observer.release(), v8::Persistent<v8::Object>::New(args.Holder()));
    return args.Holder();
}
Ejemplo n.º 2
0
    v8::Handle<v8::Value> ClientWrap::New( v8::Arguments const &args )
    {
      // This constructor should not be exposed to public javascript.
      // Therefore we assert that we are not trying to call this as a
      // normal function.
      FABRIC_ASSERT( args.IsConstructCall() );

      v8::HandleScope v8HandleScope;

      int compileGuarded = -1;
      int logWarnings = -1;
      if ( args.Length() > 0 && args[0]->IsObject() )
      {
        v8::Handle<v8::Object> opts = v8::Handle<v8::Object>::Cast( args[0] );
        v8::Handle<v8::Value> logWarnings_ = opts->Get( v8::String::New( "logWarnings" ) );
        if ( logWarnings_->IsBoolean() )
          logWarnings = logWarnings_->BooleanValue();

        v8::Handle<v8::Value> guarded = opts->Get( v8::String::New( "guarded" ) );
        if ( guarded->IsBoolean() )
          compileGuarded = guarded->BooleanValue();
      }
      ClientWrap *clientWrap = new ClientWrap( compileGuarded );
      clientWrap->Wrap(args.This());

      if ( logWarnings > -1 )
        clientWrap->m_client->getContext()->setLogWarnings( logWarnings );
      
      return v8HandleScope.Close( args.This() );
    }
Ejemplo n.º 3
0
v8::Handle<v8::Value> V8TestEventConstructor::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.TestEventConstructor.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();

    if (args.Length() < 1)
        return throwError("Not enough arguments", V8Proxy::TypeError);

    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, type, args[0]);
    TestEventConstructorInit eventInit;
    if (args.Length() >= 2) {
        EXCEPTION_BLOCK(Dictionary, options, args[1]);
        if (!fillTestEventConstructorInit(eventInit, options))
            return v8::Undefined();
    }

    RefPtr<TestEventConstructor> event = TestEventConstructor::create(type, eventInit);

    V8DOMWrapper::setDOMWrapper(args.Holder(), &info, event.get());
    return toV8(event.release(), args.Holder());
}
Ejemplo n.º 4
0
v8::Handle<v8::Value> V8AudioContext::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.AudioContext.Contructor");

    if (!args.IsConstructCall())
        return throwError("AudioContext 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("AudioContext constructor associated frame is unavailable", V8Proxy::ReferenceError);

    Document* document = frame->document();
    if (!document)
        return throwError("AudioContext constructor associated document is unavailable", V8Proxy::ReferenceError);

    RefPtr<AudioContext> audioContext;
    
    if (!args.Length()) {
        // Constructor for default AudioContext which talks to audio hardware.
        audioContext = AudioContext::create(document);
        if (!audioContext.get())
            return throwError("audio resources unavailable for AudioContext construction", V8Proxy::SyntaxError);
    } else {
        // Constructor for offline (render-target) AudioContext which renders into an AudioBuffer.
        // new AudioContext(in unsigned long numberOfChannels, in unsigned long numberOfFrames, in float sampleRate);
        if (args.Length() < 3)
            return throwError("Not enough arguments", V8Proxy::SyntaxError);

        bool ok = false;

        int32_t numberOfChannels = toInt32(args[0], ok);
        if (!ok || numberOfChannels <= 0 || numberOfChannels > 10)
            return throwError("Invalid number of channels", V8Proxy::SyntaxError);

        int32_t numberOfFrames = toInt32(args[1], ok);
        if (!ok || numberOfFrames <= 0)
            return throwError("Invalid number of frames", V8Proxy::SyntaxError);

        float sampleRate = toFloat(args[2]);
        if (sampleRate <= 0)
            return throwError("Invalid sample rate", V8Proxy::SyntaxError);

        ExceptionCode ec = 0;
        audioContext = AudioContext::createOfflineContext(document, numberOfChannels, numberOfFrames, sampleRate, ec);
        if (ec)
            return throwError(ec);
    }

    if (!audioContext.get())
        return throwError("Error creating AudioContext", V8Proxy::SyntaxError);
    
    // Transform the holder into a wrapper object for the audio context.
    V8DOMWrapper::setDOMWrapper(args.Holder(), &info, audioContext.get());
    audioContext->ref();
    
    return args.Holder();
}
Ejemplo n.º 5
0
v8::Handle<v8::Value> V8MessageChannel::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.MessageChannel.Constructor");
    // FIXME: The logic here is almost exact duplicate of V8::constructDOMObject.
    // Consider refactoring to reduce duplication.
    if (!args.IsConstructCall())
        return throwError("DOM object constructor cannot be called as a function.");

    // Get the ScriptExecutionContext (WorkerContext or Document)
    ScriptExecutionContext* context = getScriptExecutionContext();
    if (!context)
        return v8::Undefined();

    // Note: it's OK to let this RefPtr go out of scope because we also call
    // SetDOMWrapper(), which effectively holds a reference to obj.
    RefPtr<MessageChannel> obj = MessageChannel::create(context);

    v8::Local<v8::Object> messageChannel = args.Holder();

    // Create references from the MessageChannel wrapper to the two
    // MessagePort wrappers to make sure that the MessagePort wrappers
    // stay alive as long as the MessageChannel wrapper is around.
// CAPPFIX_WEB_WEBWORKERS_START
    V8DOMWrapper::setNamedHiddenReference(messageChannel, "port1", toV8(obj->port1()));
    V8DOMWrapper::setNamedHiddenReference(messageChannel, "port2", toV8(obj->port2()));
// CAPPFIX_WEB_WEBWORKERS_END

    // Setup the standard wrapper object internal fields.
    V8DOMWrapper::setDOMWrapper(messageChannel, &info, obj.get());
    return toV8(obj.release(), messageChannel);
}
Ejemplo n.º 6
0
v8::Handle<v8::Value> V8WebKitPoint::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.WebKitPoint.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();

    float x = 0;
    float y = 0;
    if (args.Length() > 1) {
        if (!args[0]->IsUndefined()) {
            x = toFloat(args[0]);
            if (isnan(x))
                x = 0;
        }
        if (!args[1]->IsUndefined()) {
            y = toFloat(args[1]);
            if (isnan(y))
                y = 0;
        }
    }
    RefPtr<WebKitPoint> point = WebKitPoint::create(x, y);
    V8DOMWrapper::setDOMWrapper(args.Holder(), &info, point.get());
    V8DOMWrapper::setJSWrapperForDOMObject(point.release(), v8::Persistent<v8::Object>::New(args.Holder()));
    return args.Holder();
}
Ejemplo n.º 7
0
void V8WebCL::constructorCustom(const v8::Arguments& 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;
	}

    // Get the script execution context.
    ScriptExecutionContext* context = (ScriptExecutionContext*)getExecutionContext(); //getScriptExecutionContext();
   // if (!context)
        //{ throwError(ReferenceError, "WebCL constructor's associated frame is not available", args.GetIsolate()); return; }

    RefPtr<WebCL> computeContext = WebCL::create(context);
	const WrapperTypeInfo &info = wrapperTypeInfo; // ScalableVision

    V8DOMWrapper::setNativeInfo(args.Holder(), &info, computeContext.get());
	//lifetime LT;
    //V8DOMWrapper::setJSWrapperForActiveDOMObject(computeContext.release(), v8::Persistent<v8::Object>::New(args.Holder()), args.GetIsolate());
	V8DOMWrapper::associateObjectWithWrapper<V8WebCL, WebCL>(computeContext.release(),&info, /*v8::Persistent<v8::Object>::New(*/args.Holder()/*)*/, args.GetIsolate(),WrapperConfiguration::Dependent );//ÅáÓ¨
    v8SetReturnValue(args, args.Holder());
	return;
}
static v8::Handle<v8::Value> V8TestNamedConstructorConstructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.TestNamedConstructor.Constructor");
    
    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.");

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    Document* document = currentDocument(BindingState::instance());

    // Make sure the document is added to the DOM Node map. Otherwise, the TestNamedConstructor instance
    // may end up being the only node in the map and get garbage-collected prematurely.
    toV8(document, args.Holder(), args.GetIsolate());

    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());

    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(), wrapper, args.GetIsolate());
    return wrapper;
  fail:
    return setDOMException(ec, args.GetIsolate());
}
Ejemplo n.º 9
0
v8::Handle<v8::Value> V8XMLHttpRequest::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.XMLHttpRequest.Constructor");

    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    // Expect no parameters.
    // Allocate a XMLHttpRequest object as its internal field.
    ScriptExecutionContext* context = getScriptExecutionContext();
    if (!context)
        return throwError(ReferenceError, "XMLHttpRequest constructor's associated context is not available", args.GetIsolate());

    RefPtr<SecurityOrigin> securityOrigin;
    if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered())
        securityOrigin = isolatedContext->securityOrigin();
    RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, securityOrigin);
    v8::Handle<v8::Object> wrapper = args.Holder();
    V8DOMWrapper::setDOMWrapper(wrapper, &info, xmlHttpRequest.get());
    V8DOMWrapper::setJSWrapperForActiveDOMObject(xmlHttpRequest.release(), wrapper);
    return wrapper;
}
v8::Handle<v8::Value> V8RTCIceCandidate::constructorCallback(const v8::Arguments& args)
{
    
    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.");

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();
    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());

    ExceptionCode ec = 0;
    V8TRYCATCH(Dictionary, dictionary, Dictionary(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined), args.GetIsolate()));
    if (!dictionary.isUndefinedOrNull() && !dictionary.isObject())
        return throwTypeError("Not an object.", args.GetIsolate());

    RefPtr<RTCIceCandidate> impl = RTCIceCandidate::create(dictionary, ec);
    v8::Handle<v8::Object> wrapper = args.Holder();
    if (ec)
        goto fail;

    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
    return wrapper;
  fail:
    return setDOMException(ec, args.GetIsolate());
}
Ejemplo n.º 11
0
v8::Handle<v8::Value> npObjectInvokeDefaultHandler(const v8::Arguments& args)
{
    if (args.IsConstructCall())
        return npObjectInvokeImpl(args, InvokeConstruct);
    else
        return npObjectInvokeImpl(args, InvokeDefault);
}
Ejemplo n.º 12
0
static v8::Handle<v8::Value> V8TestNamedConstructorConstructorCallback(const v8::Arguments& args)
{
    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    Document* document = currentDocument();

    // Make sure the document is added to the DOM Node map. Otherwise, the TestNamedConstructor instance
    // may end up being the only node in the map and get garbage-collected prematurely.
    toV8(document, args.Holder(), args.GetIsolate());

    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    ExceptionCode ec = 0;
    V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str1, args[0]);
    V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str2, args[1]);
    V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource<>, str3, argumentOrNull(args, 2));

    RefPtr<TestNamedConstructor> impl = TestNamedConstructor::createForJSConstructor(document, str1, str2, str3, ec);
    v8::Handle<v8::Object> wrapper = args.Holder();
    if (ec)
        return setDOMException(ec, args.GetIsolate());

    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &V8TestNamedConstructorConstructor::info, wrapper, args.GetIsolate(), WrapperConfiguration::Dependent);
    return wrapper;
}
v8::Handle<v8::Value> V8Custom::v8HTMLAudioElementConstructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.HTMLAudioElement.Contructor");

    if (!args.IsConstructCall())
        return throwError("DOM object constructor cannot be called as a function.");

    Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
    if (!frame)
        return throwError("Audio constructor associated frame is unavailable", V8Proxy::ReferenceError);

    Document* document = frame->document();
    if (!document)
        return throwError("Audio constructor associated document is unavailable", V8Proxy::ReferenceError);

    // Make sure the document is added to the DOM Node map. Otherwise, the HTMLAudioElement instance
    // may end up being the only node in the map and get garbage-ccollected prematurely.
    V8DOMWrapper::convertNodeToV8Object(document);

    RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(HTMLNames::audioTag, document);
    audio->setAutobuffer(true);
    if (args.Length() > 0) {
        audio->setSrc(toWebCoreString(args[0]));
        audio->scheduleLoad();
    }

    V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::NODE), audio.get());
    audio->ref();
    V8DOMWrapper::setJSWrapperForDOMNode(audio.get(), v8::Persistent<v8::Object>::New(args.Holder()));
    return args.Holder();
}
Ejemplo n.º 14
0
v8::Handle<v8::Value> V8ArrayBuffer::constructor(const v8::Arguments& args) {
	if (!args.IsConstructCall())
		return v8::ThrowException(v8::String::New("Cannot call constructor as function"));

	uscxml::ArrayBuffer* localInstance = NULL;
	if (false) {
	} else if (args.Length() == 1 &&
	           args[0]->IsUint32()) {

		unsigned long localLength = args[0]->ToNumber()->Uint32Value();
		localInstance = new uscxml::ArrayBuffer(localLength);

	}
	if (!localInstance) {
		throw V8Exception("Parameter mismatch while calling constructor for ArrayBuffer");
		return v8::Undefined();
	}

	v8::Handle<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction();
	v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());

	struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate();
	retPrivData->nativeObj = localInstance;

	retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));

	retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor);
	return retObj;
}
static v8::Handle<v8::Value> v8HTMLAudioElementConstructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.HTMLAudioElement.Contructor");

    if (!args.IsConstructCall())
        return throwError("DOM object constructor cannot be called as a function.");

    Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
    if (!frame)
        return throwError("Audio constructor associated frame is unavailable", V8Proxy::ReferenceError);

    Document* document = frame->document();
    if (!document)
        return throwError("Audio constructor associated document is unavailable", V8Proxy::ReferenceError);

    // Make sure the document is added to the DOM Node map. Otherwise, the HTMLAudioElement instance
    // may end up being the only node in the map and get garbage-collected prematurely.
    toV8(document);


    String src;
    if (args.Length() > 0)
        src = toWebCoreString(args[0]);
    RefPtr<HTMLAudioElement> audio = HTMLAudioElement::createForJSConstructor(document, src);

    V8DOMWrapper::setDOMWrapper(args.Holder(), &V8HTMLAudioElementConstructor::info, audio.get());
    audio->ref();
    V8DOMWrapper::setJSWrapperForDOMNode(audio.get(), v8::Persistent<v8::Object>::New(args.Holder()));
    return args.Holder();
}
Ejemplo n.º 16
0
v8::Handle<v8::Value> V8TestInterface::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.TestInterface.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();
    if (args.Length() < 1)
        return throwError("Not enough arguments", V8Proxy::TypeError);

    ExceptionCode ec = 0;
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str1, MAYBE_MISSING_PARAMETER(args, 0, MissingIsUndefined));
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, str2, MAYBE_MISSING_PARAMETER(args, 1, MissingIsUndefined));

    ScriptExecutionContext* context = getScriptExecutionContext();
    if (!context)
        return throwError("TestInterface constructor's associated context is not available", V8Proxy::ReferenceError);

    RefPtr<TestInterface> obj = TestInterface::create(context, str1, str2, ec);
    if (ec)
        goto fail;

    V8DOMWrapper::setDOMWrapper(args.Holder(), &info, obj.get());
    obj->ref();
    V8DOMWrapper::setJSWrapperForActiveDOMObject(obj.get(), v8::Persistent<v8::Object>::New(args.Holder()));
    return args.Holder();
  fail:
    return throwError(ec);
}
Ejemplo n.º 17
0
v8::Handle<v8::Value> V8TestSerializedScriptValueInterface::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.TestSerializedScriptValueInterface.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();
    if (args.Length() < 2)
        return throwError("Not enough arguments", V8Proxy::TypeError);
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, hello, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
    bool valueDidThrow = false;
    RefPtr<SerializedScriptValue> value = SerializedScriptValue::create(args[1], 0, 0, valueDidThrow);
    if (valueDidThrow)
        return v8::Undefined();

    RefPtr<TestSerializedScriptValueInterface> impl = TestSerializedScriptValueInterface::create(hello, value);
    v8::Handle<v8::Object> wrapper = args.Holder();

    V8DOMWrapper::setDOMWrapper(wrapper, &info, impl.get());
    impl->ref();
    V8DOMWrapper::setJSWrapperForDOMObject(impl.get(), v8::Persistent<v8::Object>::New(wrapper));
    return args.Holder();
}
v8::Handle<v8::Value> V8MutationObserver::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.MutationObserver.Constructor");

    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    if (args.Length() < 1)
        return throwNotEnoughArgumentsError(args.GetIsolate());

    v8::Local<v8::Value> arg = args[0];
    if (!arg->IsObject())
        return setDOMException(TYPE_MISMATCH_ERR, args.GetIsolate());

    ScriptExecutionContext* context = getScriptExecutionContext();

    RefPtr<MutationCallback> callback = V8MutationCallback::create(arg, context);
    RefPtr<MutationObserver> observer = MutationObserver::create(callback.release());

    v8::Handle<v8::Object> wrapper = args.Holder();
    V8DOMWrapper::setDOMWrapper(wrapper, &info, observer.get());
    V8DOMWrapper::setJSWrapperForDOMObject(observer.release(), wrapper);
    return wrapper;
}
Ejemplo n.º 19
0
v8::Handle<v8::Value> V8TestSerializedScriptValueInterface::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.TestSerializedScriptValueInterface.Constructor");

    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.");

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();
    if (args.Length() < 2)
        return throwNotEnoughArgumentsError(args.GetIsolate());
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, hello, MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined));
    MessagePortArray messagePortArrayTransferList;
    ArrayBufferArray arrayBufferArrayTransferList;
    if (args.Length() > 2) {
        if (!extractTransferables(args[2], messagePortArrayTransferList, arrayBufferArrayTransferList, args.GetIsolate()))
            return throwTypeError("Could not extract transferables");
    }
    bool dataDidThrow = false;
    RefPtr<SerializedScriptValue> data = SerializedScriptValue::create(args[1], &messagePortArrayTransferList, &arrayBufferArrayTransferList, dataDidThrow, args.GetIsolate());
    if (dataDidThrow)
        return v8Undefined();

    RefPtr<TestSerializedScriptValueInterface> impl = TestSerializedScriptValueInterface::create(hello, data, messagePortArrayTransferList);
    v8::Handle<v8::Object> wrapper = args.Holder();

    V8DOMWrapper::setDOMWrapper(wrapper, &info, impl.get());
    V8DOMWrapper::setJSWrapperForDOMObject(impl.release(), wrapper, args.GetIsolate());
    return wrapper;
}
Ejemplo n.º 20
0
v8::Handle<v8::Value> V8PeerConnection::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.PeerConnection.Constructor");

    if (!args.IsConstructCall())
        return throwError("DOM object constructor cannot be called as a function.", V8Proxy::TypeError);

    int argLength = args.Length();
    if (argLength != 2)
        return throwError("The PeerConnection constructor takes two arguments.", V8Proxy::TypeError);

    v8::TryCatch exceptionCatcher;
    String configuration = toWebCoreString(args[0]->ToString());
    if (exceptionCatcher.HasCaught())
        return throwError(exceptionCatcher.Exception());

    bool succeeded = false;
    RefPtr<SignalingCallback> signalingCallback = createFunctionOnlyCallback<V8SignalingCallback>(args[1], succeeded);
    if (!succeeded || !signalingCallback)
        return throwError("The PeerConnection constructor must be given a SignalingCallback callback.", V8Proxy::TypeError);

    Frame* frame = V8Proxy::retrieveFrameForEnteredContext();
    MediaStreamFrameController* frameController = frame ? frame->mediaStreamFrameController() : 0;

    RefPtr<PeerConnection> peerConnection;
    if (frameController)
        peerConnection = frameController->createPeerConnection(configuration, signalingCallback);

    if (!peerConnection)
        return v8::Undefined();

    V8DOMWrapper::setDOMWrapper(args.Holder(), &info, peerConnection.get());
    return toV8(peerConnection.release(), args.Holder());
}
Ejemplo n.º 21
0
v8::Handle<v8::Value> V8TestEventConstructor::constructorCallback(const v8::Arguments& args)
{
    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    return TestEventConstructorV8Internal::constructor(args);
}
v8::Handle<v8::Value> V8DOMFormData::constructorCallback(const v8::Arguments& args)
{
    
    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.");

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    return V8DOMFormData::constructorCallbackCustom(args);
}
Ejemplo n.º 23
0
v8::Handle<v8::Value> V8AdaptorFunction::invocationCallback(const v8::Arguments& args)
{
    v8::Handle<v8::Object> wrapped = v8::Handle<v8::Object>::Cast(args.Callee()->GetHiddenValue(V8HiddenPropertyName::adaptorFunctionPeer()));
    // FIXME: This can be faster if we can access underlying native callback directly.
    // We won't need this once https://bugs.webkit.org/show_bug.cgi?id=108138 is addressed.
    Vector<v8::Handle<v8::Value> > argArray(args.Length());
    for (int i = 0; i < args.Length(); ++i)
        argArray.append(args[i]);
    if (args.IsConstructCall())
        return wrapped->CallAsConstructor(argArray.size(), argArray.data());
    return wrapped->CallAsFunction(args.This(), argArray.size(), argArray.data());
}
Ejemplo n.º 24
0
v8::Handle<v8::Value> ParmenidesConstructorHelper(const v8::Arguments & args) {
    __android_log_write(ANDROID_LOG_DEBUG, "Pender NDK", "PARMENIDES CONSTRUCTOR HELPER");
    using namespace v8;
    // throw if called without `new'
    if (!args.IsConstructCall()) {
        return ThrowException(String::New("Cannot call constructor as function, use with new"));
    }

    HandleScope scope;

    return v8::String::New("demicanadian battle-felon");

}
Ejemplo n.º 25
0
v8::Handle<v8::Value> SecureCellSeal::New(const v8::Arguments& args) {
    v8::HandleScope scope;

    if (args.IsConstructCall()) {
        std::vector<uint8_t> key((uint8_t*)(node::Buffer::Data(args[0])), (uint8_t*)(node::Buffer::Data(args[0])+node::Buffer::Length(args[0])));
        SecureCellSeal* obj = new SecureCellSeal(key);
        obj->Wrap(args.This());
        return args.This();
    } else {
        const int argc = 1;
        v8::Local<v8::Value> argv[argc] = { args[0]};
        return scope.Close(constructor->NewInstance(argc, argv));
    }
}
Ejemplo n.º 26
0
Handle<Value> loadXML(const v8::Arguments& args) {
	if(!args.IsConstructCall()) {
		return v8::ThrowException(String::New("Cannot call constructor as a function"));
	}
/*	if (args.Length() != 1) {
		return v8::ThrowException(v8::String::New("Bad parameters"));
	} */
	HandleScope scope;	
	
	Shell *shell = Shell::Instance();
	Context::Scope context_scope(shell->globalContext);
	XML *newXML = new XML();
	return(scope.Close(newXML->registerObject()));
}
Ejemplo n.º 27
0
v8::Handle<v8::Value> V8TestNode::constructorCallback(const v8::Arguments& args)
{
    
    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.");

    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    RefPtr<TestNode> impl = TestNode::create();
    v8::Handle<v8::Object> wrapper = args.Holder();

    V8DOMWrapper::associateObjectWithWrapper(impl.release(), &info, wrapper, args.GetIsolate());
    return wrapper;
}
Ejemplo n.º 28
0
v8::Handle<v8::Value> V8DOMFormData::constructorCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.FormData.Constructor");

    if (!args.IsConstructCall())
        return throwError("DOM object constructor cannot be called as a function.", V8Proxy::TypeError);

    HTMLFormElement* form = 0;
    if (args.Length() > 0 && V8HTMLFormElement::HasInstance(args[0]))
        form = V8HTMLFormElement::toNative(args[0]->ToObject());
    RefPtr<DOMFormData> domFormData = DOMFormData::create(form);

    V8DOMWrapper::setDOMWrapper(args.Holder(), &info, domFormData.get());
    return toV8(domFormData.release(), args.Holder());
}
Ejemplo n.º 29
0
Handle<Value> loadHTTPClient(const v8::Arguments& args) {
	if(!args.IsConstructCall()) {
		return v8::ThrowException(String::New("Cannot call constructor as a function"));
	}
	Shell *shell = Shell::Instance();
	Context::Scope context_scope(shell->globalContext);
	HandleScope scope;
	string argument;
	HTTPClient *newHTTPClient;
	if (args.Length() == 1) {
		argument = *String::Utf8Value(args[0]);
		newHTTPClient = new HTTPClient(argument);
	} else {
		newHTTPClient = new HTTPClient();
	}
	return(scope.Close(newHTTPClient->registerObject()));
}
Ejemplo n.º 30
0
v8::Handle<v8::Value> V8CustomElementConstructor::callAsFunctionCallback(const v8::Arguments& args)
{
    if (!args.IsConstructCall())
        return throwTypeError("DOM object constructor cannot be called as a function.", args.GetIsolate());
    if (ConstructorMode::current() == ConstructorMode::WrapExistingObject)
        return args.Holder();

    CustomElementConstructor* impl = toNative(args.Holder());
    ExceptionCode ec = 0;
    RefPtr<Element> element = impl->createElement(ec);
    if (ec) {
        setDOMException(ec, args.GetIsolate());
        return v8Undefined();
    }

    return toV8(element.get(), args.Holder(), args.GetIsolate());
}