Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
  void HandleOKCallback() {
    NanScope();

    static const int argc = 2;
    Local<Value> argv[2] = { NanUndefined(), v8Value(selectResultsPtr) };
    callback->Call(argc, argv);
  }
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 6
0
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());
}
Ejemplo n.º 7
0
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);
}
Ejemplo n.º 8
0
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;
}
Ejemplo n.º 9
0
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);
}
Ejemplo n.º 11
0
String ScriptValue::toString() const
{
    v8::TryCatch block;
    v8::Handle<v8::String> string = v8Value()->ToString();
    if (block.HasCaught())
        return String();
    return v8StringToWebCoreString<String>(string, DoNotExternalize);
}
Ejemplo n.º 12
0
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);
}
Ejemplo n.º 13
0
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);
}
Ejemplo n.º 14
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));
}
Ejemplo n.º 15
0
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);
}
Ejemplo n.º 17
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);
}
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));
}
Ejemplo n.º 19
0
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);
}
Ejemplo n.º 20
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);
}
Ejemplo n.º 21
0
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;
}
Ejemplo n.º 22
0
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;
}
Ejemplo n.º 23
0
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;
}
Ejemplo n.º 24
0
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;
}
Ejemplo n.º 25
0
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());
}
Ejemplo n.º 26
0
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);
}
Ejemplo n.º 28
0
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);
}
Ejemplo n.º 29
0
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);
}