Ejemplo n.º 1
0
void WorkerScriptDebugServer::addListener(ScriptDebugListener* listener, WorkerContext* workerContext)
{
    v8::HandleScope scope;
    v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
    v8::Context::Scope contextScope(debuggerContext);

    if (!m_listenersMap.size()) {
        // FIXME: synchronize access to this code.
        ensureDebuggerScriptCompiled();
        ASSERT(!m_debuggerScript.get()->IsUndefined());
        v8::Debug::SetDebugEventListener2(&WorkerScriptDebugServer::v8DebugEventCallback, v8::External::New(this));
    }
    m_listenersMap.set(workerContext, listener);
    
    WorkerContextExecutionProxy* proxy = workerContext->script()->proxy();
    if (!proxy)
        return;
    v8::Handle<v8::Context> context = proxy->context();

    v8::Handle<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("getWorkerScripts")));
    v8::Handle<v8::Value> argv[] = { v8::Handle<v8::Value>() };
    v8::Handle<v8::Value> value = getScriptsFunction->Call(m_debuggerScript.get(), 0, argv);
    if (value.IsEmpty())
        return;
    ASSERT(!value->IsUndefined() && value->IsArray());
    v8::Handle<v8::Array> scriptsArray = v8::Handle<v8::Array>::Cast(value);
    for (unsigned i = 0; i < scriptsArray->Length(); ++i)
        dispatchDidParseSource(listener, v8::Handle<v8::Object>::Cast(scriptsArray->Get(v8::Integer::New(i))));
}
Ejemplo n.º 2
0
// static
WorkerContextProxy* WebWorkerClientImpl::createWorkerContextProxy(Worker* worker)
{
    // Special behavior for multiple workers per process.
    // FIXME: v8 doesn't support more than one workers per process.
    // if (!worker->scriptExecutionContext()->isDocument())
    //     return new WorkerMessagingProxy(worker);

    WebWorker* webWorker = 0;
    WebWorkerClientImpl* proxy = new WebWorkerClientImpl(worker);

    if (worker->scriptExecutionContext()->isDocument()) {
        Document* document = static_cast<Document*>(
                                 worker->scriptExecutionContext());
        WebFrameImpl* webFrame = WebFrameImpl::fromFrame(document->frame());
        webWorker = webFrame->client()->createWorker(webFrame, proxy);
    } else {
        WorkerContextExecutionProxy* currentContext =
            WorkerContextExecutionProxy::retrieve();
        if (!currentContext) {
            ASSERT_NOT_REACHED();
            return 0;
        }

        DedicatedWorkerThread* thread =
            static_cast<DedicatedWorkerThread*>(currentContext->workerContext()->thread());
        WorkerObjectProxy* workerObjectProxy = &thread->workerObjectProxy();
        WebWorkerImpl* impl = reinterpret_cast<WebWorkerImpl*>(workerObjectProxy);
        webWorker = impl->client()->createWorker(proxy);
    }

    proxy->setWebWorker(webWorker);
    return proxy;
}
void V8WorkerContextEventListener::handleEvent(ScriptExecutionContext* context, Event* event)
{
    if (!context)
        return;

    // The callback function on XMLHttpRequest can clear the event listener and destroys 'this' object. Keep a local reference to it.
    // See issue 889829.
    RefPtr<V8AbstractEventListener> protect(this);

    v8::HandleScope handleScope;

    WorkerContextExecutionProxy* proxy = workerProxy(context);
    if (!proxy)
        return;

    v8::Handle<v8::Context> v8Context = proxy->context();
    if (v8Context.IsEmpty())
        return;

    // Enter the V8 context in which to perform the event handling.
    v8::Context::Scope scope(v8Context);

    // Get the V8 wrapper for the event object.
    v8::Handle<v8::Value> jsEvent = toV8(event);

    invokeEventHandler(context, event, jsEvent);
}
Ejemplo n.º 4
0
ScriptState* scriptStateFromWorkerContext(WorkerContext* workerContext)
{
    WorkerContextExecutionProxy* proxy = workerContext->script()->proxy();
    if (!proxy)
        return 0;

    v8::HandleScope handleScope;
    v8::Local<v8::Context> context = proxy->context();
    return ScriptState::forContext(context);
}
Ejemplo n.º 5
0
v8::Local<v8::Function> V8DOMWrapper::getConstructor(V8ClassIndex::V8WrapperType type, WorkerContext*)
{
    WorkerContextExecutionProxy* proxy = WorkerContextExecutionProxy::retrieve();
    if (!proxy)
        return v8::Local<v8::Function>();

    v8::Handle<v8::Context> context = proxy->context();
    if (context.IsEmpty())
        return v8::Local<v8::Function>();

    return getConstructorForContext(type, context);
}
v8::Handle<v8::Value> toV8(WorkerContext* impl)
{
    if (!impl)
        return v8::Null();

    WorkerContextExecutionProxy* proxy = impl->script()->proxy();
    if (!proxy)
        return v8::Null();

    v8::Handle<v8::Object> global = proxy->context()->Global();
    ASSERT(!global.IsEmpty());
    return global;
}
Ejemplo n.º 7
0
v8::Local<v8::Function> V8DOMWrapper::getConstructor(WrapperTypeInfo* type, WorkerContext*)
{
    WorkerScriptController* controller = WorkerScriptController::controllerForContext();
    WorkerContextExecutionProxy* proxy = controller ? controller->proxy() : 0;
    if (!proxy)
        return v8::Local<v8::Function>();

    v8::Handle<v8::Context> context = proxy->context();
    if (context.IsEmpty())
        return v8::Local<v8::Function>();

    return getConstructorForContext(type, context);
}
Ejemplo n.º 8
0
v8::Handle<v8::Value> toV8(WorkerContext* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
    // Notice that we explicitly ignore creationContext because the WorkerContext is its own creationContext.

    if (!impl)
        return v8NullWithCheck(isolate);

    WorkerContextExecutionProxy* proxy = impl->script()->proxy();
    if (!proxy)
        return v8NullWithCheck(isolate);

    v8::Handle<v8::Object> global = proxy->context()->Global();
    ASSERT(!global.IsEmpty());
    return global;
}
Ejemplo n.º 9
0
ScriptExecutionContext* getScriptExecutionContext(ScriptState* scriptState)
{
#if ENABLE(WORKERS)
    WorkerContextExecutionProxy* proxy = WorkerContextExecutionProxy::retrieve();
    if (proxy)
        return proxy->workerContext()->scriptExecutionContext();
#endif

    if (scriptState)
        return scriptState->frame()->document()->scriptExecutionContext();
    else {
        Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
        if (frame)
            return frame->document()->scriptExecutionContext();
    }

    return 0;
}
Ejemplo n.º 10
0
v8::Handle<v8::Value> SetTimeoutOrInterval(const v8::Arguments& args, bool singleShot)
{
    WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder());

    int argumentCount = args.Length();
    if (argumentCount < 1)
        return v8::Undefined();

    v8::Handle<v8::Value> function = args[0];
    int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0;
    int timerId;

    WorkerContextExecutionProxy* proxy = workerContext->script()->proxy();
    if (!proxy)
        return v8::Undefined();

    v8::Handle<v8::Context> v8Context = proxy->context();
    if (function->IsString()) {
        if (ContentSecurityPolicy* policy = workerContext->contentSecurityPolicy()) {
            if (!policy->allowEval())
                return v8Integer(0, args.GetIsolate());
        }
        WTF::String stringFunction = toWebCoreString(function);
        timerId = DOMTimer::install(workerContext, adoptPtr(new ScheduledAction(v8Context, stringFunction, workerContext->url())), timeout, singleShot);
    } else if (function->IsFunction()) {
        size_t paramCount = argumentCount >= 2 ? argumentCount - 2 : 0;
        v8::Local<v8::Value>* params = 0;
        if (paramCount > 0) {
            params = new v8::Local<v8::Value>[paramCount];
            for (size_t i = 0; i < paramCount; ++i)
                params[i] = args[i+2];
        }
        // ScheduledAction takes ownership of actual params and releases them in its destructor.
        OwnPtr<ScheduledAction> action = adoptPtr(new ScheduledAction(v8Context, v8::Handle<v8::Function>::Cast(function), paramCount, params));
        // FIXME: We should use a OwnArrayPtr for params.
        delete [] params;
        timerId = DOMTimer::install(workerContext, action.release(), timeout, singleShot);
    } else
        return v8::Undefined();

    return v8Integer(timerId, args.GetIsolate());
}
Ejemplo n.º 11
0
ScriptExecutionContext* getScriptExecutionContext(ScriptState* scriptState)
{
#if ENABLE(WORKERS)
    WorkerContextExecutionProxy* proxy = WorkerContextExecutionProxy::retrieve();
    if (proxy)
        return proxy->workerContext()->scriptExecutionContext();
#endif

    Frame* frame;
    if (scriptState) {
        v8::HandleScope handleScope;
        frame = V8Proxy::retrieveFrame(scriptState->context());
    } else
        frame = V8Proxy::retrieveFrameForCurrentContext();

    if (frame)
        return frame->document()->scriptExecutionContext();

    return 0;
}
Ejemplo n.º 12
0
v8::Handle<v8::Value> SetTimeoutOrInterval(const v8::Arguments& args, bool singleShot)
{
    WorkerContext* workerContext = V8WorkerContext::toNative(args.Holder());

    int argumentCount = args.Length();
    if (argumentCount < 1)
        return v8::Undefined();

    v8::Handle<v8::Value> function = args[0];
    int32_t timeout = argumentCount >= 2 ? args[1]->Int32Value() : 0;
    int timerId;

    WorkerContextExecutionProxy* proxy = workerContext->script()->proxy();
    if (!proxy)
        return v8::Undefined();

    v8::Handle<v8::Context> v8Context = proxy->context();
    if (function->IsString()) {
        WTF::String stringFunction = toWebCoreString(function);
        timerId = DOMTimer::install(workerContext, new ScheduledAction(v8Context, stringFunction, workerContext->url()), timeout, singleShot);
    } else if (function->IsFunction()) {
        size_t paramCount = argumentCount >= 2 ? argumentCount - 2 : 0;
        v8::Local<v8::Value>* params = 0;
        if (paramCount > 0) {
            params = new v8::Local<v8::Value>[paramCount];
            for (size_t i = 0; i < paramCount; ++i)
                params[i] = args[i+2];
        }
        // ScheduledAction takes ownership of actual params and releases them in its destructor.
        ScheduledAction* action = new ScheduledAction(v8Context, v8::Handle<v8::Function>::Cast(function), paramCount, params);
        delete [] params;
        timerId = DOMTimer::install(workerContext, action, timeout, singleShot);
    } else
        return v8::Undefined();

    return v8::Integer::New(timerId);
}
Ejemplo n.º 13
0
v8::Local<v8::Function> V8DOMWrapper::constructorForType(WrapperTypeInfo* type, WorkerContext*)
{
    WorkerScriptController* controller = WorkerScriptController::controllerForContext();
    WorkerContextExecutionProxy* proxy = controller ? controller->proxy() : 0;
    return proxy ? proxy->perContextData()->constructorForType(type) : v8::Local<v8::Function>();
}
Ejemplo n.º 14
0
V8BindingPerContextData* V8DOMWrapper::perContextData(WorkerContext*)
{
    WorkerScriptController* controller = WorkerScriptController::controllerForContext();
    WorkerContextExecutionProxy* proxy = controller ? controller->proxy() : 0;
    return proxy ? proxy->perContextData() : 0;
}