Exemple #1
0
void WebCLKernel::setArg(unsigned index, const ScriptValue& value, ExceptionState& es)
{
    v8::Isolate* isolate = value.isolate();
    v8::Handle<v8::Value> object(value.v8Value());
    if (V8WebCLMemoryObject::hasInstance(object, isolate)) {
        WebCLMemoryObject* memoryObject;
        memoryObject = V8WebCLMemoryObject::toImplWithTypeCheck(isolate, object);
        setArg(index, memoryObject, es);
        return;
    }

    if (V8WebCLSampler::hasInstance(object, isolate)) {
        WebCLSampler* sampler;
        sampler = V8WebCLSampler::toImplWithTypeCheck(isolate, object);
        setArg(index, sampler, es);
        return;
    }

    if (V8ArrayBufferView::hasInstance(object, isolate)) {
        DOMArrayBufferView* arrayBufferView;
        arrayBufferView = object->IsArrayBufferView() ? V8ArrayBufferView::toImpl(v8::Handle<v8::ArrayBufferView>::Cast(object)) : 0;
        setArg(index, arrayBufferView, es);
        return;
    }

    es.throwWebCLException(WebCLException::INVALID_ARG_VALUE, WebCLException::invalidArgValueMessage);
}
Exemple #2
0
ScriptPromise::ScriptPromise(const ScriptValue& value)
{
    if (value.hasNoValue())
        return;
    v8::Local<v8::Value> v8Value(value.v8Value());
    v8::Isolate* isolate = value.isolate();
    if (V8PromiseCustom::isPromise(v8Value, isolate)) {
        m_promise = value;
        return;
    }
    m_promise = ScriptValue(V8PromiseCustom::toPromise(v8Value, isolate), isolate);
}
Exemple #3
0
 ScriptValue call(ScriptValue v) override
 {
     RefPtr<ReadingContext> readingContext(m_readingContext);
     if (!readingContext)
         return v;
     bool done;
     v8::Local<v8::Value> item = v.v8Value();
     ASSERT(item->IsObject());
     v8::Local<v8::Value> value = v8CallOrCrash(v8UnpackIteratorResult(v.getScriptState(), item.As<v8::Object>(), &done));
     if (done) {
         readingContext->onReadDone();
         return v;
     }
     if (!V8Uint8Array::hasInstance(value, v.isolate())) {
         readingContext->onRejected();
         return ScriptValue();
     }
     readingContext->onRead(V8Uint8Array::toImpl(value.As<v8::Object>()));
     return v;
 }
Exemple #4
0
ScriptPromise ScriptPromise::cast(const ScriptValue& value)
{
    if (value.isEmpty())
        return ScriptPromise();
    v8::Local<v8::Value> v8Value(value.v8Value());
    v8::Isolate* isolate = value.isolate();
    if (V8PromiseCustom::isPromise(v8Value, isolate) || v8Value->IsPromise()) {
        return ScriptPromise(value.scriptState(), v8Value);
    }
    if (RuntimeEnabledFeatures::scriptPromiseOnV8PromiseEnabled()) {
        v8::Local<v8::Promise::Resolver> resolver = v8::Promise::Resolver::New(isolate);
        if (resolver.IsEmpty()) {
            // The Promise constructor may return an empty value, for example
            // when the stack is exhausted.
            return ScriptPromise();
        }
        resolver->Resolve(v8Value);
        return ScriptPromise(value.scriptState(), resolver->GetPromise());
    }
    return ScriptPromise(value.scriptState(), V8PromiseCustom::toPromise(v8Value, isolate));
}
Exemple #5
0
void ForeignFetchRespondWithObserver::responseWasFulfilled(
    const ScriptValue& value) {
  ASSERT(getExecutionContext());
  ExceptionState exceptionState(value.isolate(), ExceptionState::UnknownContext,
                                "ForeignFetchEvent", "respondWith");
  ForeignFetchResponse foreignFetchResponse =
      ScriptValue::to<ForeignFetchResponse>(toIsolate(getExecutionContext()),
                                            value, exceptionState);
  if (exceptionState.hadException()) {
    exceptionState.clearException();
    responseWasRejected(WebServiceWorkerResponseErrorNoForeignFetchResponse);
    return;
  }

  Response* response = foreignFetchResponse.response();
  const FetchResponseData* internalResponse = response->response();
  const bool isOpaque =
      internalResponse->getType() == FetchResponseData::OpaqueType ||
      internalResponse->getType() == FetchResponseData::OpaqueRedirectType;
  if (internalResponse->getType() != FetchResponseData::DefaultType)
    internalResponse = internalResponse->internalResponse();

  if (!foreignFetchResponse.hasOrigin()) {
    if (foreignFetchResponse.hasHeaders() &&
        !foreignFetchResponse.headers().isEmpty()) {
      responseWasRejected(
          WebServiceWorkerResponseErrorForeignFetchHeadersWithoutOrigin);
      return;
    }

    // If response isn't already opaque, make it opaque.
    if (!isOpaque) {
      FetchResponseData* opaqueData =
          internalResponse->createOpaqueFilteredResponse();
      response = Response::create(getExecutionContext(), opaqueData);
    }
  } else if (m_requestOrigin->toString() != foreignFetchResponse.origin()) {
    responseWasRejected(
        WebServiceWorkerResponseErrorForeignFetchMismatchedOrigin);
    return;
  } else if (!isOpaque) {
    HTTPHeaderSet headers;
    if (foreignFetchResponse.hasHeaders()) {
      for (const String& header : foreignFetchResponse.headers())
        headers.add(header);
      if (response->response()->getType() == FetchResponseData::CORSType) {
        const HTTPHeaderSet& existingHeaders =
            response->response()->corsExposedHeaderNames();
        HTTPHeaderSet headersToRemove;
        for (HTTPHeaderSet::iterator it = headers.begin(); it != headers.end();
             ++it) {
          if (!existingHeaders.contains(*it))
            headersToRemove.add(*it);
        }
        headers.removeAll(headersToRemove);
      }
    }
    FetchResponseData* responseData =
        internalResponse->createCORSFilteredResponse(headers);
    response = Response::create(getExecutionContext(), responseData);
  }

  RespondWithObserver::responseWasFulfilled(
      ScriptValue::from(value.getScriptState(), response));
}