bool SerializedScriptValueReaderForModules::readCryptoKey(
    v8::Local<v8::Value>* value) {
  uint32_t rawKeyType;
  if (!doReadUint32(&rawKeyType))
    return false;

  WebCryptoKeyAlgorithm algorithm;
  WebCryptoKeyType type = WebCryptoKeyTypeSecret;

  switch (static_cast<CryptoKeySubTag>(rawKeyType)) {
    case AesKeyTag:
      if (!doReadAesKey(algorithm, type))
        return false;
      break;
    case HmacKeyTag:
      if (!doReadHmacKey(algorithm, type))
        return false;
      break;
    case RsaHashedKeyTag:
      if (!doReadRsaHashedKey(algorithm, type))
        return false;
      break;
    case EcKeyTag:
      if (!doReadEcKey(algorithm, type))
        return false;
      break;
    case NoParamsKeyTag:
      if (!doReadKeyWithoutParams(algorithm, type))
        return false;
      break;
    default:
      return false;
  }

  WebCryptoKeyUsageMask usages;
  bool extractable;
  if (!doReadKeyUsages(usages, extractable))
    return false;

  uint32_t keyDataLength;
  if (!doReadUint32(&keyDataLength))
    return false;

  if (position() + keyDataLength > length())
    return false;

  const uint8_t* keyData = allocate(keyDataLength);
  WebCryptoKey key = WebCryptoKey::createNull();
  if (!Platform::current()->crypto()->deserializeKeyForClone(
          algorithm, type, extractable, usages, keyData, keyDataLength, key)) {
    return false;
  }

  *value = toV8(CryptoKey::create(key), getScriptState()->context()->Global(),
                isolate());
  return !value->IsEmpty();
}
예제 #2
0
ScriptString ScriptString::concatenateWith(const String& string)
{
    v8::Isolate* nonNullIsolate = isolate();
    v8::HandleScope handleScope(nonNullIsolate);
    v8::Handle<v8::String> targetString = v8String(nonNullIsolate, string);
    if (isEmpty())
        return ScriptString(nonNullIsolate, targetString);
    return ScriptString(nonNullIsolate, v8::String::Concat(v8Value(), targetString));
}
V8AbstractEventListener::~V8AbstractEventListener()
{
    if (!m_listener.isEmpty()) {
        v8::HandleScope scope(m_isolate);
        V8EventListenerList::clearWrapper(m_listener.newLocal(isolate()), m_isAttribute, isolate());
    }
    if (isMainThread())
        InspectorCounters::decrementCounter(InspectorCounters::JSEventListenerCounter);
}
ScriptValueSerializer::StateBase* ScriptValueSerializerForModules::doSerializeValue(v8::Local<v8::Value> value, ScriptValueSerializer::StateBase* next)
{
    bool isDOMFileSystem = V8DOMFileSystem::hasInstance(value, isolate());
    if (isDOMFileSystem || V8CryptoKey::hasInstance(value, isolate())) {
        v8::Local<v8::Object> jsObject = value.As<v8::Object>();
        if (jsObject.IsEmpty())
            return handleError(DataCloneError, "An object could not be cloned.", next);
        greyObject(jsObject);

        if (isDOMFileSystem)
            return writeDOMFileSystem(value, next);

        if (!writeCryptoKey(value))
            return handleError(DataCloneError, "Couldn't serialize key data", next);
        return 0;
    }
    return ScriptValueSerializer::doSerializeValue(value, next);
}
예제 #5
0
PassRefPtr<SharedPersistent<v8::Object>> ScriptController::createPluginWrapper(Widget* widget)
{
    ASSERT(widget);

    if (!widget->isPluginView())
        return nullptr;

    v8::HandleScope handleScope(isolate());
    v8::Local<v8::Object> scriptableObject = toPluginView(widget)->scriptableObject(isolate());

    if (scriptableObject.IsEmpty())
        return nullptr;

    // LocalFrame Memory Management for NPObjects
    // -------------------------------------
    // NPObjects are treated differently than other objects wrapped by JS.
    // NPObjects can be created either by the browser (e.g. the main
    // window object) or by the plugin (the main plugin object
    // for a HTMLEmbedElement). Further, unlike most DOM Objects, the frame
    // is especially careful to ensure NPObjects terminate at frame teardown because
    // if a plugin leaks a reference, it could leak its objects (or the browser's objects).
    //
    // The LocalFrame maintains a list of plugin objects (m_pluginObjects)
    // which it can use to quickly find the wrapped embed object.
    //
    // Inside the NPRuntime, we've added a few methods for registering
    // wrapped NPObjects. The purpose of the registration is because
    // javascript garbage collection is non-deterministic, yet we need to
    // be able to tear down the plugin objects immediately. When an object
    // is registered, javascript can use it. When the object is destroyed,
    // or when the object's "owning" object is destroyed, the object will
    // be un-registered, and the javascript engine must not use it.
    //
    // Inside the javascript engine, the engine can keep a reference to the
    // NPObject as part of its wrapper. However, before accessing the object
    // it must consult the _NPN_Registry.

    if (isWrappedNPObject(scriptableObject)) {
        // Track the plugin object. We've been given a reference to the object.
        m_pluginObjects.set(widget, v8ObjectToNPObject(scriptableObject));
    }

    return SharedPersistent<v8::Object>::create(scriptableObject, isolate());
}
TEST_F(SerializedScriptValueTest, FileConstructorFile)
{
    RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create();
    RefPtrWillBeRawPtr<File> originalFile = File::create("hello.txt", 12345678.0, blobDataHandle);
    ASSERT_FALSE(originalFile->hasBackingFile());
    ASSERT_EQ(File::IsNotUserVisible, originalFile->userVisibility());
    ASSERT_EQ("hello.txt", originalFile->name());

    v8::Handle<v8::Value> v8OriginalFile = toV8(originalFile.get(), creationContext(), isolate());
    RefPtr<SerializedScriptValue> serializedScriptValue =
        SerializedScriptValue::create(v8OriginalFile, nullptr, nullptr, ASSERT_NO_EXCEPTION, isolate());
    v8::Handle<v8::Value> v8File = serializedScriptValue->deserialize(isolate());

    ASSERT_TRUE(V8File::hasInstance(v8File, isolate()));
    File* file = V8File::toImpl(v8::Handle<v8::Object>::Cast(v8File));
    EXPECT_FALSE(file->hasBackingFile());
    EXPECT_EQ(File::IsNotUserVisible, file->userVisibility());
    EXPECT_EQ("hello.txt", file->name());
}
void V8WorkerGlobalScopeEventListener::handleEvent(ScriptState* scriptState, Event* event)
{
    // The callback function on XMLHttpRequest can clear the event listener and destroys 'this' object. Keep a local reference to it.
    // See issue 889829.
    RefPtrWillBeRawPtr<V8AbstractEventListener> protect(this);

    WorkerOrWorkletScriptController* script = toWorkerGlobalScope(scriptState->executionContext())->script();
    if (!script)
        return;

    ScriptState::Scope scope(scriptState);

    // Get the V8 wrapper for the event object.
    v8::Local<v8::Value> jsEvent = toV8(event, scriptState->context()->Global(), isolate());
    if (jsEvent.IsEmpty())
        return;

    invokeEventHandler(scriptState, event, v8::Local<v8::Value>::New(isolate(), jsEvent));
}
예제 #8
0
TEST_F(ScriptPromiseTest, reject)
{
    String onFulfilled, onRejected;

    ScriptValue value = ScriptValue(scriptState(), v8String(isolate(), "hello"));
    ScriptPromise promise = ScriptPromise::reject(scriptState(), ScriptValue(value));
    promise.then(Function::create(isolate(), &onFulfilled), Function::create(isolate(), &onRejected));

    ASSERT_FALSE(promise.isEmpty());
    ASSERT_TRUE(promise.v8Value()->IsPromise());

    EXPECT_EQ(String(), onFulfilled);
    EXPECT_EQ(String(), onRejected);

    isolate()->RunMicrotasks();

    EXPECT_EQ(String(), onFulfilled);
    EXPECT_EQ("hello", onRejected);
}
예제 #9
0
ScriptString ScriptString::concatenateWith(const String& string)
{
    v8::Isolate* nonNullIsolate = isolate();
    v8::HandleScope handleScope(nonNullIsolate);
    v8::Handle<v8::String> b = v8String(nonNullIsolate, string);
    if (hasNoValue())
        return ScriptString(b, nonNullIsolate);
    v8::Handle<v8::String> a = v8::Handle<v8::String>::Cast(v8Value());
    return ScriptString(v8::String::Concat(a, b), nonNullIsolate);
}
void V8WorkerGlobalScopeEventListener::handleEvent(ScriptState* scriptState,
                                                   Event* event) {
  WorkerOrWorkletScriptController* script =
      toWorkerGlobalScope(scriptState->getExecutionContext())
          ->scriptController();
  if (!script)
    return;

  ScriptState::Scope scope(scriptState);

  // Get the V8 wrapper for the event object.
  v8::Local<v8::Value> jsEvent =
      toV8(event, scriptState->context()->Global(), isolate());
  if (jsEvent.IsEmpty())
    return;

  invokeEventHandler(scriptState, event,
                     v8::Local<v8::Value>::New(isolate(), jsEvent));
}
예제 #11
0
ScriptValue ScriptState::getFromExtrasExports(const char* name) {
  v8::HandleScope handleScope(m_isolate);
  v8::Local<v8::Value> v8Value;
  if (!context()
           ->GetExtrasBindingObject()
           ->Get(context(), v8AtomicString(isolate(), name))
           .ToLocal(&v8Value))
    return ScriptValue();
  return ScriptValue(this, v8Value);
}
예제 #12
0
v8::Local<v8::Object> V8PerIsolateData::findInstanceInPrototypeChain(const WrapperTypeInfo* info, v8::Local<v8::Value> value, DOMTemplateMap& domTemplateMap)
{
    if (value.IsEmpty() || !value->IsObject())
        return v8::Local<v8::Object>();
    DOMTemplateMap::iterator result = domTemplateMap.find(info);
    if (result == domTemplateMap.end())
        return v8::Local<v8::Object>();
    v8::Local<v8::FunctionTemplate> templ = result->value.Get(isolate());
    return v8::Local<v8::Object>::Cast(value)->FindInstanceInPrototypeChain(templ);
}
TEST_F(SerializedScriptValueTest, UserSelectedFile)
{
    String filePath = testing::blinkRootDir();
    filePath.append("/Source/bindings/core/v8/SerializedScriptValueTest.cpp");
    File* originalFile = File::create(filePath);
    ASSERT_TRUE(originalFile->hasBackingFile());
    ASSERT_EQ(File::IsUserVisible, originalFile->userVisibility());
    ASSERT_EQ(filePath, originalFile->path());

    v8::Local<v8::Value> v8OriginalFile = toV8(originalFile, creationContext(), isolate());
    RefPtr<SerializedScriptValue> serializedScriptValue =
    SerializedScriptValueFactory::instance().create(isolate(), v8OriginalFile, nullptr, nullptr, nullptr, ASSERT_NO_EXCEPTION);
    v8::Local<v8::Value> v8File = serializedScriptValue->deserialize(isolate());

    ASSERT_TRUE(V8File::hasInstance(v8File, isolate()));
    File* file = V8File::toImpl(v8::Local<v8::Object>::Cast(v8File));
    EXPECT_TRUE(file->hasBackingFile());
    EXPECT_EQ(File::IsUserVisible, file->userVisibility());
    EXPECT_EQ(filePath, file->path());
}
예제 #14
0
void V8AbstractEventListener::setListenerObject(
    v8::Local<v8::Object> listener) {
    ASSERT(m_listener.isEmpty());
    // Balanced in wrapperCleared xor clearListenerObject.
    if (m_workerGlobalScope) {
        m_workerGlobalScope->registerEventListener(this);
    } else {
        m_keepAlive = this;
    }
    m_listener.set(isolate(), listener, this, &wrapperCleared);
}
예제 #15
0
void WorkerScriptController::scheduleExecutionTermination()
{
    // The mutex provides a memory barrier to ensure that once
    // termination is scheduled, isExecutionTerminating will
    // accurately reflect that state when called from another thread.
    {
        MutexLocker locker(m_scheduledTerminationMutex);
        m_executionScheduledToTerminate = true;
    }
    v8::V8::TerminateExecution(isolate());
}
TEST_F(SerializedScriptValueTest, UserSelectedFile)
{
    String filePath = Platform::current()->unitTestSupport()->webKitRootDir();
    filePath.append("/Source/bindings/core/v8/SerializedScriptValueTest.cpp");
    RefPtrWillBeRawPtr<File> originalFile = File::create(filePath);
    ASSERT_TRUE(originalFile->hasBackingFile());
    ASSERT_EQ(File::IsUserVisible, originalFile->userVisibility());
    ASSERT_EQ(filePath, originalFile->path());

    v8::Handle<v8::Value> v8OriginalFile = toV8(originalFile.get(), creationContext(), isolate());
    RefPtr<SerializedScriptValue> serializedScriptValue =
        SerializedScriptValue::create(v8OriginalFile, nullptr, nullptr, ASSERT_NO_EXCEPTION, isolate());
    v8::Handle<v8::Value> v8File = serializedScriptValue->deserialize(isolate());

    ASSERT_TRUE(V8File::hasInstance(v8File, isolate()));
    File* file = V8File::toImpl(v8::Handle<v8::Object>::Cast(v8File));
    EXPECT_TRUE(file->hasBackingFile());
    EXPECT_EQ(File::IsUserVisible, file->userVisibility());
    EXPECT_EQ(filePath, file->path());
}
예제 #17
0
// Create a V8 object with an interceptor of NPObjectPropertyGetter.
bool ScriptController::bindToWindowObject(LocalFrame* frame, const String& key, NPObject* object)
{
    ScriptState* scriptState = ScriptState::forMainWorld(frame);
    if (!scriptState->contextIsValid())
        return false;

    ScriptState::Scope scope(scriptState);
    v8::Local<v8::Object> value = createV8ObjectForNPObject(isolate(), object, 0);

    // Attach to the global object.
    return v8CallBoolean(scriptState->context()->Global()->Set(scriptState->context(), v8String(isolate(), key), value));
}
예제 #18
0
파일: isolator.hpp 프로젝트: Bbarrett/mesos
  TestIsolatorProcess(const Option<CommandInfo>& _commandInfo)
    : commandInfo(_commandInfo)
  {
    EXPECT_CALL(*this, watch(testing::_))
      .WillRepeatedly(testing::Return(promise.future()));

    EXPECT_CALL(*this, isolate(testing::_, testing::_))
      .WillRepeatedly(testing::Return(Nothing()));

    EXPECT_CALL(*this, cleanup(testing::_))
      .WillRepeatedly(testing::Return(Nothing()));
  }
예제 #19
0
TEST_F(ScriptPromiseTest, castNonPromise)
{
    String onFulfilled1, onFulfilled2, onRejected1, onRejected2;

    ScriptValue value = ScriptValue(scriptState(), v8String(isolate(), "hello"));
    ScriptPromise promise1 = ScriptPromise::cast(scriptState(), ScriptValue(value));
    ScriptPromise promise2 = ScriptPromise::cast(scriptState(), ScriptValue(value));
    promise1.then(Function::create(isolate(), &onFulfilled1), Function::create(isolate(), &onRejected1));
    promise2.then(Function::create(isolate(), &onFulfilled2), Function::create(isolate(), &onRejected2));

    ASSERT_FALSE(promise1.isEmpty());
    ASSERT_FALSE(promise2.isEmpty());
    EXPECT_NE(promise1.v8Value(), promise2.v8Value());

    ASSERT_TRUE(promise1.v8Value()->IsPromise());
    ASSERT_TRUE(promise2.v8Value()->IsPromise());

    EXPECT_EQ(String(), onFulfilled1);
    EXPECT_EQ(String(), onFulfilled2);
    EXPECT_EQ(String(), onRejected1);
    EXPECT_EQ(String(), onRejected2);

    isolate()->RunMicrotasks();

    EXPECT_EQ("hello", onFulfilled1);
    EXPECT_EQ("hello", onFulfilled2);
    EXPECT_EQ(String(), onRejected1);
    EXPECT_EQ(String(), onRejected2);
}
예제 #20
0
TEST_F(ScriptPromiseTest, thenReject)
{
    RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState());
    ScriptPromise promise = resolver->promise();
    String onFulfilled, onRejected;
    promise.then(Function::create(isolate(), &onFulfilled), Function::create(isolate(), &onRejected));

    ASSERT_FALSE(promise.isEmpty());
    EXPECT_EQ(String(), onFulfilled);
    EXPECT_EQ(String(), onRejected);

    isolate()->RunMicrotasks();
    resolver->reject("hello");

    EXPECT_EQ(String(), onFulfilled);
    EXPECT_EQ(String(), onRejected);

    isolate()->RunMicrotasks();

    EXPECT_EQ(String(), onFulfilled);
    EXPECT_EQ("hello", onRejected);
}
예제 #21
0
v8::Local<v8::Function> V8EventListener::getListenerFunction(
    ScriptState* scriptState) {
    v8::Local<v8::Object> listener =
        getListenerObject(scriptState->getExecutionContext());

    // Has the listener been disposed?
    if (listener.IsEmpty())
        return v8::Local<v8::Function>();

    if (listener->IsFunction())
        return v8::Local<v8::Function>::Cast(listener);

    // The EventHandler callback function type (used for event handler
    // attributes in HTML) has [TreatNonObjectAsNull], which implies that
    // non-function objects should be treated as no-op functions that return
    // undefined.
    if (isAttribute())
        return v8::Local<v8::Function>();

    // Getting the handleEvent property can runs script in the getter.
    if (ScriptForbiddenScope::isScriptForbidden()) {
        V8ThrowException::throwError(isolate(), "Script execution is forbidden.");
        return v8::Local<v8::Function>();
    }

    if (listener->IsObject()) {
        // Check that no exceptions were thrown when getting the
        // handleEvent property and that the value is a function.
        v8::Local<v8::Value> property;
        if (listener
                ->Get(scriptState->context(),
                      v8AtomicString(isolate(), "handleEvent"))
                .ToLocal(&property) &&
                property->IsFunction())
            return v8::Local<v8::Function>::Cast(property);
    }

    return v8::Local<v8::Function>();
}
예제 #22
0
int			if_key_replace(char *new_var, t_list **g_env)
{
	t_list	*temp;
	char	*name;
	char	*value;

	temp = *g_env;
	name = isolate(new_var, 0);
	if (name == NULL)
		return (1);
	value = isolate(new_var, 1);
	while (temp != NULL)
	{
		if ((ft_strcmp(((t_env *)temp->content)->name, name)) == 0)
			break ;
		temp = temp->next;
	}
	ft_strdel(&name);
	if (temp == NULL)
		return (1);
	return (replace_key_value(temp, new_var, value));
}
void V8AbstractEventListener::handleEvent(ExecutionContext*, Event* event)
{
    // Don't reenter V8 if execution was terminated in this instance of V8.
    if (scriptState()->executionContext()->isJSExecutionForbidden())
        return;

    ASSERT(event);

    // 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);

    if (scriptState()->contextIsEmpty())
        return;
    ScriptState::Scope scope(scriptState());

    // Get the V8 wrapper for the event object.
    v8::Handle<v8::Value> jsEvent = toV8(event, scriptState()->context()->Global(), isolate());
    if (jsEvent.IsEmpty())
        return;
    invokeEventHandler(event, v8::Local<v8::Value>::New(isolate(), jsEvent));
}
예제 #24
0
HashMap<String, String> Dictionary::getOwnPropertiesAsStringHashMap(
    ExceptionState& exceptionState) const {
  if (m_dictionaryObject.IsEmpty())
    return HashMap<String, String>();

  v8::TryCatch tryCatch(isolate());
  v8::Local<v8::Array> propertyNames;
  if (!m_dictionaryObject->GetOwnPropertyNames(v8Context())
           .ToLocal(&propertyNames)) {
    exceptionState.rethrowV8Exception(tryCatch.Exception());
    return HashMap<String, String>();
  }

  HashMap<String, String> ownProperties;
  for (uint32_t i = 0; i < propertyNames->Length(); ++i) {
    v8::Local<v8::String> key;
    if (!getStringValueInArray(v8Context(), propertyNames, i).ToLocal(&key)) {
      exceptionState.rethrowV8Exception(tryCatch.Exception());
      return HashMap<String, String>();
    }
    V8StringResource<> stringKey(key);
    if (!stringKey.prepare(isolate(), exceptionState))
      return HashMap<String, String>();

    v8::Local<v8::Value> value;
    if (!m_dictionaryObject->Get(v8Context(), key).ToLocal(&value)) {
      exceptionState.rethrowV8Exception(tryCatch.Exception());
      return HashMap<String, String>();
    }
    V8StringResource<> stringValue(value);
    if (!stringValue.prepare(isolate(), exceptionState))
      return HashMap<String, String>();

    if (!static_cast<const String&>(stringKey).isEmpty())
      ownProperties.set(stringKey, stringValue);
  }

  return ownProperties;
}
예제 #25
0
V8PerIsolateData::V8PerIsolateData()
    : m_destructionPending(false)
    , m_stringCache(adoptPtr(new StringCache(isolate())))
    , m_constructorMode(ConstructorMode::CreateNewObject)
    , m_recursionLevel(0)
    , m_isHandlingRecursionLevelError(false)
    , m_isReportingException(false)
#if ENABLE(ASSERT)
    , m_internalScriptRecursionLevel(0)
#endif
    , m_performingMicrotaskCheckpoint(false)
    , m_scriptDebugger(nullptr)
{
    // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone.
    isolate()->Enter();
#if ENABLE(ASSERT)
    if (!runningUnitTest())
        isolate()->AddCallCompletedCallback(&assertV8RecursionScope);
#endif
    if (isMainThread())
        mainThreadPerIsolateData = this;
    isolate()->SetUseCounterCallback(&useCounterCallback);
}
예제 #26
0
bool Dictionary::getInternal(const v8::Local<v8::Value>& key,
                             v8::Local<v8::Value>& result) const {
  if (m_dictionaryObject.IsEmpty())
    return false;

  if (!v8CallBoolean(m_dictionaryObject->Has(v8Context(), key)))
    return false;

  // Swallow a possible exception in v8::Object::Get().
  // TODO(bashi,yukishiino): Should rethrow the exception.
  // http://crbug.com/666661
  v8::TryCatch tryCatch(isolate());
  return m_dictionaryObject->Get(v8Context(), key).ToLocal(&result);
}
void V8AbstractEventListener::invokeEventHandler(ScriptState* scriptState, Event* event, v8::Local<v8::Value> jsEvent)
{
    if (!event->canBeDispatchedInWorld(world()))
        return;

    v8::Local<v8::Value> returnValue;
    {
        // Catch exceptions thrown in the event handler so they do not propagate to javascript code that caused the event to fire.
        v8::TryCatch tryCatch(isolate());
        tryCatch.SetVerbose(true);

        // Save the old 'event' property so we can restore it later.
        v8::Local<v8::Value> savedEvent = V8HiddenValue::getHiddenValue(scriptState, scriptState->context()->Global(), V8HiddenValue::event(isolate()));
        tryCatch.Reset();

        // Make the event available in the global object, so LocalDOMWindow can expose it.
        V8HiddenValue::setHiddenValue(scriptState, scriptState->context()->Global(), V8HiddenValue::event(isolate()), jsEvent);
        tryCatch.Reset();

        returnValue = callListenerFunction(scriptState, jsEvent, event);
        if (tryCatch.HasCaught())
            event->target()->uncaughtExceptionInEventHandler();

        if (!tryCatch.CanContinue()) { // Result of TerminateExecution().
            if (scriptState->executionContext()->isWorkerGlobalScope())
                toWorkerGlobalScope(scriptState->executionContext())->scriptController()->forbidExecution();
            return;
        }
        tryCatch.Reset();

        // Restore the old event. This must be done for all exit paths through this method.
        if (savedEvent.IsEmpty())
            V8HiddenValue::setHiddenValue(scriptState, scriptState->context()->Global(), V8HiddenValue::event(isolate()), v8::Undefined(isolate()));
        else
            V8HiddenValue::setHiddenValue(scriptState, scriptState->context()->Global(), V8HiddenValue::event(isolate()), savedEvent);
        tryCatch.Reset();
    }

    if (returnValue.IsEmpty())
        return;

    if (m_isAttribute && !returnValue->IsNull() && !returnValue->IsUndefined() && event->isBeforeUnloadEvent()) {
        TOSTRING_VOID(V8StringResource<>, stringReturnValue, returnValue);
        toBeforeUnloadEvent(event)->setReturnValue(stringReturnValue);
    }

    if (m_isAttribute && shouldPreventDefault(returnValue))
        event->preventDefault();
}
ScriptValueSerializer::StateBase*
ScriptValueSerializerForModules::doSerializeObject(
    v8::Local<v8::Object> jsObject,
    StateBase* next) {
  DCHECK(!jsObject.IsEmpty());

  if (V8DOMFileSystem::hasInstance(jsObject, isolate())) {
    greyObject(jsObject);
    return writeDOMFileSystem(jsObject, next);
  }
  if (V8CryptoKey::hasInstance(jsObject, isolate())) {
    greyObject(jsObject);
    if (!writeCryptoKey(jsObject))
      return handleError(Status::DataCloneError, "Couldn't serialize key data",
                         next);
    return nullptr;
  }
  if (V8RTCCertificate::hasInstance(jsObject, isolate())) {
    greyObject(jsObject);
    return writeRTCCertificate(jsObject, next);
  }

  return ScriptValueSerializer::doSerializeObject(jsObject, next);
}
예제 #29
0
v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Local<v8::Context> context, const ScriptSourceCode& source, AccessControlStatus corsStatus, double* compilationFinishTime)
{
    TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "EvaluateScript", "data", InspectorEvaluateScriptEvent::data(frame(), source.url().string(), source.startLine()));
    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvaluateScript(frame(), source.url().string(), source.startLine());

    v8::Local<v8::Value> result;
    {
        V8CacheOptions v8CacheOptions(V8CacheOptionsDefault);
        if (frame()->settings())
            v8CacheOptions = frame()->settings()->v8CacheOptions();

        // Isolate exceptions that occur when compiling and executing
        // the code. These exceptions should not interfere with
        // javascript code we might evaluate from C++ when returning
        // from here.
        v8::TryCatch tryCatch;
        tryCatch.SetVerbose(true);

        v8::Local<v8::Script> script;
        if (!v8Call(V8ScriptRunner::compileScript(source, isolate(), corsStatus, v8CacheOptions), script, tryCatch))
            return result;

        if (compilationFinishTime) {
            *compilationFinishTime = WTF::monotonicallyIncreasingTime();
        }
        // Keep LocalFrame (and therefore ScriptController) alive.
        RefPtrWillBeRawPtr<LocalFrame> protect(frame());
        if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, frame()->document()), result, tryCatch))
            return result;
    }

    InspectorInstrumentation::didEvaluateScript(cookie);
    TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data());

    return result;
}
bool SerializedScriptValueReaderForModules::readDOMFileSystem(v8::Local<v8::Value>* value)
{
    uint32_t type;
    String name;
    String url;
    if (!doReadUint32(&type))
        return false;
    if (!readWebCoreString(&name))
        return false;
    if (!readWebCoreString(&url))
        return false;
    DOMFileSystem* fs = DOMFileSystem::create(scriptState()->executionContext(), name, static_cast<FileSystemType>(type), KURL(ParsedURLString, url));
    *value = toV8(fs, scriptState()->context()->Global(), isolate());
    return true;
}