Local<Object> EventStream::Event::v8Object() { NanEscapableScope(); Local<Object> eventPayload(NanNew<Object>()); eventPayload->Set(NanNew("key"), v8Value(entryEventPtr->getKey())); eventPayload->Set(NanNew("oldValue"), v8Value(entryEventPtr->getOldValue())); eventPayload->Set(NanNew("newValue"), v8Value(entryEventPtr->getNewValue())); return NanEscapeScope(eventPayload); }
void HandleOKCallback() { NanScope(); static const int argc = 2; Local<Value> argv[2] = { NanUndefined(), v8Value(selectResultsPtr) }; callback->Call(argc, argv); }
String ScriptString::flattenToString() { if (isEmpty()) return String(); v8::HandleScope handleScope(isolate()); return v8StringToWebCoreString<String>(v8Value(), Externalize); }
ScriptValue idbKeyToScriptValue(ScriptState* scriptState, IDBKey* key) { v8::Isolate* isolate = scriptState->isolate(); v8::HandleScope handleScope(isolate); v8::Handle<v8::Value> v8Value(toV8(key, scriptState->context()->Global(), isolate)); return ScriptValue(scriptState, v8Value); }
IDBKey* scriptValueToIDBKey(v8::Isolate* isolate, const ScriptValue& scriptValue) { ASSERT(isolate->InContext()); v8::HandleScope handleScope(isolate); v8::Handle<v8::Value> v8Value(scriptValue.v8Value()); return createIDBKeyFromValue(isolate, v8Value); }
PassRefPtr<JSONValue> ScriptValue::toJSONValue(ScriptState* scriptState) const { v8::HandleScope handleScope(scriptState->isolate()); // v8::Object::GetPropertyNames() expects current context to be not null. v8::Context::Scope contextScope(scriptState->context()); return v8ToJSONValue(v8Value(), JSONValue::maxDepth, scriptState->isolate()); }
void InjectedScript::getProperties(ErrorString* errorString, v8::Local<v8::Object> object, const String16& groupName, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, std::unique_ptr<Array<PropertyDescriptor>>* properties, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { v8::HandleScope handles(m_context->isolate()); V8FunctionCall function(m_context->inspector(), m_context->context(), v8Value(), "getProperties"); function.appendArgument(object); function.appendArgument(groupName); function.appendArgument(ownProperties); function.appendArgument(accessorPropertiesOnly); function.appendArgument(generatePreview); v8::TryCatch tryCatch(m_context->isolate()); v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); if (tryCatch.HasCaught()) { *exceptionDetails = createExceptionDetails(tryCatch.Message()); // FIXME: make properties optional *properties = Array<PropertyDescriptor>::create(); return; } std::unique_ptr<protocol::Value> protocolValue = toProtocolValue(m_context->context(), resultValue); if (hasInternalError(errorString, !protocolValue)) return; protocol::ErrorSupport errors(errorString); std::unique_ptr<Array<PropertyDescriptor>> result = Array<PropertyDescriptor>::parse(protocolValue.get(), &errors); if (!hasInternalError(errorString, errors.hasErrors())) *properties = std::move(result); }
bool injectIDBKeyIntoScriptValue(DOMRequestState*, PassRefPtr<IDBKey> key, ScriptValue& value, const IDBKeyPath& keyPath) { IDB_TRACE("injectIDBKeyIntoScriptValue"); ASSERT(v8::Context::InContext()); ASSERT(keyPath.type() == IDBKeyPath::StringType); Vector<String> keyPathElements; IDBKeyPathParseError error; IDBParseKeyPath(keyPath.string(), keyPathElements, error); ASSERT(error == IDBKeyPathParseErrorNone); if (!keyPathElements.size()) return 0; v8::HandleScope handleScope; v8::Handle<v8::Value> v8Value(value.v8Value()); v8::Handle<v8::Value> parent(ensureNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size() - 1)); if (parent.IsEmpty()) return false; if (!set(parent, keyPathElements.last(), toV8(key.get()))) return false; return true; }
ScriptValue idbKeyToScriptValue(DOMRequestState* state, PassRefPtr<IDBKey> key) { ASSERT(v8::Context::InContext()); v8::HandleScope handleScope; v8::Handle<v8::Value> v8Value(toV8(key.get())); return ScriptValue(v8Value); }
String ScriptString::flattenToString() const { if (hasNoValue()) return String(); v8::HandleScope handleScope; v8::Handle<v8::String> value = v8::Handle<v8::String>::Cast(v8Value()); return v8StringToWebCoreString<String>(value, Externalize); }
String ScriptValue::toString() const { v8::TryCatch block; v8::Handle<v8::String> string = v8Value()->ToString(); if (block.HasCaught()) return String(); return v8StringToWebCoreString<String>(string, DoNotExternalize); }
PassRefPtr<IDBKey> scriptValueToIDBKey(DOMRequestState* state, const ScriptValue& scriptValue) { v8::Isolate* isolate = state ? state->context()->GetIsolate() : v8::Isolate::GetCurrent(); ASSERT(isolate->InContext()); v8::HandleScope handleScope(isolate); v8::Handle<v8::Value> v8Value(scriptValue.v8Value()); return createIDBKeyFromValue(v8Value, isolate); }
void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) { v8::HandleScope handles(m_context->isolate()); V8FunctionCall function(m_context->inspector(), m_context->context(), v8Value(), "setCustomObjectFormatterEnabled"); function.appendArgument(enabled); bool hadException = false; function.call(hadException); DCHECK(!hadException); }
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)); }
ScriptValue idbKeyToScriptValue(DOMRequestState* state, PassRefPtr<IDBKey> key) { v8::Isolate* isolate = state ? state->context()->GetIsolate() : v8::Isolate::GetCurrent(); ASSERT(isolate->InContext()); v8::Local<v8::Context> context = state ? state->context() : isolate->GetCurrentContext(); v8::HandleScope handleScope(isolate); v8::Handle<v8::Value> v8Value(toV8(key.get(), context->Global(), isolate)); return ScriptValue(v8Value, isolate); }
PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> value, const Vector<IDBKeyPathElement>& keyPath) { LocalContext localContext; v8::Handle<v8::Value> v8Value(value->deserialize()); v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPath, keyPath.size())); if (v8Key.IsEmpty()) return 0; return createIDBKeyFromValue(v8Key); }
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); }
ScriptString ScriptString::concatenateWith(const String& string) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HandleScope handleScope(isolate); v8::Handle<v8::String> b = v8String(string, isolate); if (hasNoValue()) return ScriptString(b); v8::Handle<v8::String> a = v8::Handle<v8::String>::Cast(v8Value()); return ScriptString(v8::String::Concat(a, b)); }
bool InjectedScript::wrapObjectsInArray(ErrorString* errorString, v8::Local<v8::Array> array, const String16& groupName, bool forceValueType, bool generatePreview) const { V8FunctionCall function(m_context->inspector(), m_context->context(), v8Value(), "wrapObjectsInArray"); function.appendArgument(array); function.appendArgument(groupName); function.appendArgument(forceValueType); function.appendArgument(generatePreview); bool hadException = false; function.call(hadException); return !hasInternalError(errorString, hadException); }
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); }
bool ScriptValue::getString(String& result) const { if (hasNoValue()) return false; v8::HandleScope handleScope(m_isolate); v8::Handle<v8::Value> string = v8Value(); if (string.IsEmpty() || !string->IsString()) return false; result = toCoreString(string.As<v8::String>()); return true; }
bool ScriptValue::getString(String& result, v8::Isolate* isolate) const { if (hasNoValue()) return false; if (!m_value->isString()) return false; v8::HandleScope handleScope(isolate); result = toWebCoreString(v8Value()); return true; }
bool ScriptValue::toString(String& result) const { if (isEmpty()) return false; ScriptState::Scope scope(m_scriptState.get()); v8::Local<v8::Value> string = v8Value(); if (string.IsEmpty() || !string->IsString()) return false; result = toCoreString(v8::Local<v8::String>::Cast(string)); return true; }
v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(ErrorString* errorString, v8::Local<v8::Value> value, const String16& groupName, bool forceValueType, bool generatePreview) const { V8FunctionCall function(m_context->inspector(), m_context->context(), v8Value(), "wrapObject"); function.appendArgument(value); function.appendArgument(groupName); function.appendArgument(forceValueType); function.appendArgument(generatePreview); bool hadException = false; v8::Local<v8::Value> r = function.call(hadException); if (hasInternalError(errorString, hadException || r.IsEmpty())) return v8::MaybeLocal<v8::Value>(); return r; }
bool canInjectIDBKeyIntoScriptValue(DOMRequestState* state, const ScriptValue& scriptValue, const IDBKeyPath& keyPath) { IDB_TRACE("canInjectIDBKeyIntoScriptValue"); ASSERT(keyPath.type() == IDBKeyPath::StringType); Vector<String> keyPathElements; IDBKeyPathParseError error; IDBParseKeyPath(keyPath.string(), keyPathElements, error); ASSERT(error == IDBKeyPathParseErrorNone); if (!keyPathElements.size()) return false; v8::Handle<v8::Value> v8Value(scriptValue.v8Value()); return canInjectNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size() - 1, state->context()->GetIsolate()); }
static PassRefPtr<IDBKey> createIDBKeyFromScriptValueAndKeyPath(const ScriptValue& value, const String& keyPath, v8::Isolate* isolate) { Vector<String> keyPathElements; IDBKeyPathParseError error; IDBParseKeyPath(keyPath, keyPathElements, error); ASSERT(error == IDBKeyPathParseErrorNone); ASSERT(isolate->InContext()); v8::HandleScope handleScope(isolate); v8::Handle<v8::Value> v8Value(value.v8Value()); v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size(), isolate)); if (v8Key.IsEmpty()) return 0; return createIDBKeyFromValue(v8Key, isolate); }
static IDBKey* createIDBKeyFromScriptValueAndKeyPathInternal(v8::Isolate* isolate, const ScriptValue& value, const String& keyPath, bool allowExperimentalTypes) { Vector<String> keyPathElements; IDBKeyPathParseError error; IDBParseKeyPath(keyPath, keyPathElements, error); ASSERT(error == IDBKeyPathParseErrorNone); ASSERT(isolate->InContext()); v8::HandleScope handleScope(isolate); v8::Handle<v8::Value> v8Value(value.v8Value()); v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(isolate, v8Value, keyPathElements, keyPathElements.size())); if (v8Key.IsEmpty()) return 0; return createIDBKeyFromValue(isolate, v8Key, allowExperimentalTypes); }
std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local<v8::Value> table, v8::Local<v8::Value> columns) const { v8::HandleScope handles(m_context->isolate()); V8FunctionCall function(m_context->inspector(), m_context->context(), v8Value(), "wrapTable"); function.appendArgument(table); if (columns.IsEmpty()) function.appendArgument(false); else function.appendArgument(columns); bool hadException = false; v8::Local<v8::Value> r = function.call(hadException); if (hadException) return nullptr; protocol::ErrorSupport errors; return protocol::Runtime::RemoteObject::parse(toProtocolValue(m_context->context(), r).get(), &errors); }
static PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> prpValue, const String& keyPath) { Vector<String> keyPathElements; IDBKeyPathParseError error; IDBParseKeyPath(keyPath, keyPathElements, error); ASSERT(error == IDBKeyPathParseErrorNone); RefPtr<SerializedScriptValue> value = prpValue; V8AuxiliaryContext context; v8::Handle<v8::Value> v8Value(value->deserialize()); v8::Handle<v8::Value> v8Key(getNthValueOnKeyPath(v8Value, keyPathElements, keyPathElements.size())); if (v8Key.IsEmpty()) return 0; return createIDBKeyFromValue(v8Key); }
PassRefPtr<SerializedScriptValue> injectIDBKeyIntoSerializedValue(PassRefPtr<IDBKey> key, PassRefPtr<SerializedScriptValue> value, const Vector<IDBKeyPathElement>& keyPath) { LocalContext localContext; if (!keyPath.size()) return 0; v8::Handle<v8::Value> v8Value(value->deserialize()); v8::Handle<v8::Value> parent(getNthValueOnKeyPath(v8Value, keyPath, keyPath.size() - 1)); if (parent.IsEmpty()) return 0; if (!set(parent, keyPath.last(), toV8(key.get()))) return 0; return SerializedScriptValue::create(v8Value); }