コード例 #1
0
bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplementedAs& impl, v8::Local<v8::Object> dictionary, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
{
    if (impl.hasDerivedStringMember()) {
        if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8String(isolate, "derivedStringMember"), v8String(isolate, impl.derivedStringMember()))))
            return false;
    }

    if (impl.hasDerivedStringMemberWithDefault()) {
        if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8String(isolate, "derivedStringMemberWithDefault"), v8String(isolate, impl.derivedStringMemberWithDefault()))))
            return false;
    } else {
        if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8String(isolate, "derivedStringMemberWithDefault"), v8String(isolate, String("default string value")))))
            return false;
    }

    if (impl.hasRequiredLongMember()) {
        if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8String(isolate, "requiredLongMember"), v8::Integer::New(isolate, impl.requiredLongMember()))))
            return false;
    } else {
        ASSERT_NOT_REACHED();
    }

    if (impl.hasStringOrDoubleSequenceMember()) {
        if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8String(isolate, "stringOrDoubleSequenceMember"), toV8(impl.stringOrDoubleSequenceMember(), creationContext, isolate))))
            return false;
    }

    return true;
}
コード例 #2
0
bool toV8TestDictionaryDerivedImplementedAs(const TestDictionaryDerivedImplementedAs& impl, v8::Local<v8::Object> dictionary, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
{
    // TODO(bashi): Use ForceSet() instead of Set(). http://crbug.com/476720
    if (impl.hasDerivedStringMember()) {
        if (!v8CallBoolean(dictionary->Set(isolate->GetCurrentContext(), v8String(isolate, "derivedStringMember"), v8String(isolate, impl.derivedStringMember()))))
            return false;
    }

    if (impl.hasDerivedStringMemberWithDefault()) {
        if (!v8CallBoolean(dictionary->Set(isolate->GetCurrentContext(), v8String(isolate, "derivedStringMemberWithDefault"), v8String(isolate, impl.derivedStringMemberWithDefault()))))
            return false;
    } else {
        if (!v8CallBoolean(dictionary->Set(isolate->GetCurrentContext(), v8String(isolate, "derivedStringMemberWithDefault"), v8String(isolate, String("default string value")))))
            return false;
    }

    if (impl.hasRequiredLongMember()) {
        if (!v8CallBoolean(dictionary->Set(isolate->GetCurrentContext(), v8String(isolate, "requiredLongMember"), v8::Integer::New(isolate, impl.requiredLongMember()))))
            return false;
    } else {
        ASSERT_NOT_REACHED();
    }

    return true;
}
コード例 #3
0
v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(
    const WrapperTypeInfo* type) {
  ASSERT(!m_errorPrototype.isEmpty());

  v8::Local<v8::Context> currentContext = context();
  v8::Context::Scope scope(currentContext);
  const DOMWrapperWorld& world = DOMWrapperWorld::world(currentContext);
  // We shouldn't reach this point for the types that are implemented in v8 such
  // as typed arrays and hence don't have domTemplateFunction.
  ASSERT(type->domTemplateFunction);
  v8::Local<v8::FunctionTemplate> interfaceTemplate =
      type->domTemplate(m_isolate, world);
  // Getting the function might fail if we're running out of stack or memory.
  v8::Local<v8::Function> interfaceObject;
  if (!interfaceTemplate->GetFunction(currentContext).ToLocal(&interfaceObject))
    return v8::Local<v8::Function>();

  if (type->parentClass) {
    v8::Local<v8::Object> prototypeTemplate =
        constructorForType(type->parentClass);
    if (prototypeTemplate.IsEmpty())
      return v8::Local<v8::Function>();
    if (!v8CallBoolean(
            interfaceObject->SetPrototype(currentContext, prototypeTemplate)))
      return v8::Local<v8::Function>();
  }

  v8::Local<v8::Value> prototypeValue;
  if (!interfaceObject
           ->Get(currentContext, v8AtomicString(m_isolate, "prototype"))
           .ToLocal(&prototypeValue) ||
      !prototypeValue->IsObject())
    return v8::Local<v8::Function>();
  v8::Local<v8::Object> prototypeObject = prototypeValue.As<v8::Object>();
  if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcount &&
      type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeObjectPrototype)
    prototypeObject->SetAlignedPointerInInternalField(
        v8PrototypeTypeIndex, const_cast<WrapperTypeInfo*>(type));
  type->preparePrototypeAndInterfaceObject(currentContext, world,
                                           prototypeObject, interfaceObject,
                                           interfaceTemplate);
  if (type->wrapperTypePrototype ==
      WrapperTypeInfo::WrapperTypeExceptionPrototype) {
    if (!v8CallBoolean(prototypeObject->SetPrototype(
            currentContext, m_errorPrototype.newLocal(m_isolate))))
      return v8::Local<v8::Function>();
  }

  // Origin Trials
  installConditionalFeatures(type, ScriptState::from(currentContext),
                             prototypeObject, interfaceObject);

  m_constructorMap.Set(type, interfaceObject);

  return interfaceObject;
}
コード例 #4
0
v8::Local<v8::Object> v8IteratorResultValue(v8::Isolate* isolate, bool done, v8::Local<v8::Value> value)
{
    v8::Local<v8::Object> result = v8::Object::New(isolate);
    if (value.IsEmpty())
        value = v8::Undefined(isolate);
    if (!v8CallBoolean(result->Set(isolate->GetCurrentContext(), v8String(isolate, "done"), v8Boolean(done, isolate)))
        || !v8CallBoolean(result->Set(isolate->GetCurrentContext(), v8String(isolate, "value"), value)))
        return v8::Local<v8::Object>();
    return result;
}
コード例 #5
0
static v8::Local<v8::Object> wrapInShadowTemplate(v8::Local<v8::Object> wrapper, ScriptWrappable* scriptWrappable, v8::Isolate* isolate)
{
    static int shadowTemplateKey; // This address is used for a key to look up the dom template.
    V8PerIsolateData* data = V8PerIsolateData::from(isolate);
    v8::Local<v8::FunctionTemplate> shadowTemplate = data->existingDOMTemplate(&shadowTemplateKey);
    if (shadowTemplate.IsEmpty()) {
        shadowTemplate = v8::FunctionTemplate::New(isolate);
        if (shadowTemplate.IsEmpty())
            return v8::Local<v8::Object>();
        shadowTemplate->SetClassName(v8AtomicString(isolate, "HTMLDocument"));
        shadowTemplate->Inherit(V8HTMLDocument::domTemplate(isolate));
        shadowTemplate->InstanceTemplate()->SetInternalFieldCount(V8HTMLDocument::internalFieldCount);
        data->setDOMTemplate(&shadowTemplateKey, shadowTemplate);
    }

    v8::Local<v8::Function> shadowConstructor;
    if (!shadowTemplate->GetFunction(isolate->GetCurrentContext()).ToLocal(&shadowConstructor))
        return v8::Local<v8::Object>();

    v8::Local<v8::Object> shadow;
    if (!V8ScriptRunner::instantiateObject(isolate, shadowConstructor).ToLocal(&shadow))
        return v8::Local<v8::Object>();
    if (!v8CallBoolean(shadow->SetPrototype(isolate->GetCurrentContext(), wrapper)))
        return v8::Local<v8::Object>();
    V8DOMWrapper::setNativeInfo(wrapper, &V8HTMLDocument::wrapperTypeInfo, scriptWrappable);
    return shadow;
}
コード例 #6
0
void WindowProxy::updateDocumentProperty()
{
    if (!m_world->isMainWorld())
        return;

    if (m_frame->isRemoteFrame()) {
        return;
    }

    ScriptState::Scope scope(m_scriptState.get());
    v8::Local<v8::Context> context = m_scriptState->context();
    LocalFrame* frame = toLocalFrame(m_frame);
    v8::Local<v8::Value> documentWrapper = toV8(frame->document(), context->Global(), context->GetIsolate());
    if (documentWrapper.IsEmpty())
        return;
    ASSERT(documentWrapper == m_document.newLocal(m_isolate) || m_document.isEmpty());
    if (m_document.isEmpty())
        updateDocumentWrapper(v8::Local<v8::Object>::Cast(documentWrapper));
    checkDocumentWrapper(m_document.newLocal(m_isolate), frame->document());

    ASSERT(documentWrapper->IsObject());
    // TODO(jochen): Don't replace the accessor with a data value. We need a way to tell v8 that the accessor's return value won't change after this point.
    if (!v8CallBoolean(context->Global()->ForceSet(context, v8AtomicString(m_isolate, "document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete))))
        return;

    // We also stash a reference to the document on the inner global object so that
    // LocalDOMWindow objects we obtain from JavaScript references are guaranteed to have
    // live Document objects.
    V8HiddenValue::setHiddenValue(m_scriptState.get(), v8::Local<v8::Object>::Cast(context->Global()->GetPrototype()), V8HiddenValue::document(m_isolate), documentWrapper);
}
コード例 #7
0
bool WorkerScriptController::initializeContextIfNeeded()
{
    v8::HandleScope handleScope(isolate());

    if (isContextInitialized())
        return true;

    v8::Local<v8::Context> context = v8::Context::New(isolate());
    if (context.IsEmpty())
        return false;

    m_scriptState = ScriptState::create(context, m_world);

    ScriptState::Scope scope(m_scriptState.get());

    // Name new context for debugging.
    WorkerScriptDebugServer::setContextDebugData(context);

    // Create a new JS object and use it as the prototype for the shadow global object.
    const WrapperTypeInfo* wrapperTypeInfo = m_workerGlobalScope.wrapperTypeInfo();
    v8::Local<v8::Function> workerGlobalScopeConstructor = m_scriptState->perContextData()->constructorForType(wrapperTypeInfo);
    v8::Local<v8::Object> jsWorkerGlobalScope = V8ObjectConstructor::newInstance(isolate(), workerGlobalScopeConstructor);
    if (jsWorkerGlobalScope.IsEmpty()) {
        m_scriptState->disposePerContextData();
        return false;
    }

    V8DOMWrapper::associateObjectWithWrapper(isolate(), &m_workerGlobalScope, wrapperTypeInfo, jsWorkerGlobalScope);

    // Insert the object instance as the prototype of the shadow object.
    v8::Local<v8::Object> globalObject = v8::Local<v8::Object>::Cast(m_scriptState->context()->Global()->GetPrototype());
    return v8CallBoolean(globalObject->SetPrototype(context, jsWorkerGlobalScope));
}
コード例 #8
0
void WindowProxy::updateDocumentProperty()
{
    if (!m_world->isMainWorld())
        return;

    if (m_frame->isRemoteFrame()) {
        return;
    }

    ScriptState::Scope scope(m_scriptState.get());
    v8::Local<v8::Context> context = m_scriptState->context();
    LocalFrame* frame = toLocalFrame(m_frame);
    v8::Local<v8::Value> documentWrapper = toV8(frame->document(), context->Global(), context->GetIsolate());
    if (documentWrapper.IsEmpty())
        return;
    ASSERT(documentWrapper == m_document.newLocal(m_isolate) || m_document.isEmpty());
    if (m_document.isEmpty())
        updateDocumentWrapper(v8::Local<v8::Object>::Cast(documentWrapper));
    checkDocumentWrapper(m_document.newLocal(m_isolate), frame->document());

    ASSERT(documentWrapper->IsObject());
    // TODO(jochen): Don't replace the accessor with a data value. We need a way to tell v8 that the accessor's return value won't change after this point.
    if (!v8CallBoolean(context->Global()->ForceSet(context, v8AtomicString(m_isolate, "document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete))))
        return;
}
コード例 #9
0
void WindowProxy::updateDocumentProperty()
{
    if (!m_world->isMainWorld())
        return;

    if (m_frame->isRemoteFrame()) {
        return;
    }

    ScriptState::Scope scope(m_scriptState.get());
    v8::Local<v8::Context> context = m_scriptState->context();
    LocalFrame* frame = toLocalFrame(m_frame);
    v8::Local<v8::Value> documentWrapper = toV8(frame->document(), context->Global(), context->GetIsolate());
    if (documentWrapper.IsEmpty())
        return;
    ASSERT(documentWrapper == m_document.newLocal(m_isolate) || m_document.isEmpty());
    if (m_document.isEmpty())
        updateDocumentWrapper(v8::Local<v8::Object>::Cast(documentWrapper));
    checkDocumentWrapper(m_document.newLocal(m_isolate), frame->document());

    ASSERT(documentWrapper->IsObject());
    // TODO(bashi): Avoid using ForceSet(). When we use accessors to implement
    // attributes, we may be able to remove updateDocumentProperty().
    if (!v8CallBoolean(context->Global()->ForceSet(context, v8AtomicString(m_isolate, "document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete))))
        return;

    // We also stash a reference to the document on the inner global object so that
    // LocalDOMWindow objects we obtain from JavaScript references are guaranteed to have
    // live Document objects.
    V8HiddenValue::setHiddenValue(m_isolate, toInnerGlobalObject(context), V8HiddenValue::document(m_isolate), documentWrapper);
}
コード例 #10
0
ファイル: Dictionary.cpp プロジェクト: mirror/chromium
bool Dictionary::getOwnPropertiesAsStringHashMap(
    HashMap<String, String>& hashMap) const {
  v8::Local<v8::Object> object;
  if (!toObject(object))
    return false;

  v8::Local<v8::Array> properties;
  if (!object->GetOwnPropertyNames(v8Context()).ToLocal(&properties))
    return false;
  for (uint32_t i = 0; i < properties->Length(); ++i) {
    v8::Local<v8::String> key;
    if (!propertyKey(v8Context(), properties, i, key))
      continue;
    if (!v8CallBoolean(object->Has(v8Context(), key)))
      continue;

    v8::Local<v8::Value> value;
    if (!object->Get(v8Context(), key).ToLocal(&value))
      continue;
    TOSTRING_DEFAULT(V8StringResource<>, stringKey, key, false);
    TOSTRING_DEFAULT(V8StringResource<>, stringValue, value, false);
    if (!static_cast<const String&>(stringKey).isEmpty())
      hashMap.set(stringKey, stringValue);
  }

  return true;
}
コード例 #11
0
bool V0CustomElementConstructorBuilder::validateOptions(const AtomicString& type, QualifiedName& tagName, ExceptionState& exceptionState)
{
    ASSERT(m_prototype.IsEmpty());

    v8::TryCatch tryCatch(m_scriptState->isolate());

    if (!m_scriptState->perContextData()) {
        // FIXME: This should generate an InvalidContext exception at a later point.
        V0CustomElementException::throwException(V0CustomElementException::ContextDestroyedCheckingPrototype, type, exceptionState);
        tryCatch.ReThrow();
        return false;
    }

    if (m_options.hasPrototype()) {
        ASSERT(m_options.prototype().isObject());
        m_prototype = m_options.prototype().v8Value().As<v8::Object>();
    } else {
        m_prototype = v8::Object::New(m_scriptState->isolate());
        v8::Local<v8::Object> basePrototype = m_scriptState->perContextData()->prototypeForType(&V8HTMLElement::wrapperTypeInfo);
        if (!basePrototype.IsEmpty()) {
            if (!v8CallBoolean(m_prototype->SetPrototype(m_scriptState->context(), basePrototype)))
                return false;
        }
    }

    AtomicString namespaceURI = HTMLNames::xhtmlNamespaceURI;
    if (hasValidPrototypeChainFor(&V8SVGElement::wrapperTypeInfo))
        namespaceURI = SVGNames::svgNamespaceURI;

    ASSERT(!tryCatch.HasCaught());

    AtomicString localName;

    if (m_options.hasExtends()) {
        localName = AtomicString(m_options.extends().lower());

        if (!Document::isValidName(localName)) {
            V0CustomElementException::throwException(V0CustomElementException::ExtendsIsInvalidName, type, exceptionState);
            tryCatch.ReThrow();
            return false;
        }
        if (V0CustomElement::isValidName(localName)) {
            V0CustomElementException::throwException(V0CustomElementException::ExtendsIsCustomElementName, type, exceptionState);
            tryCatch.ReThrow();
            return false;
        }
    } else {
        if (namespaceURI == SVGNames::svgNamespaceURI) {
            V0CustomElementException::throwException(V0CustomElementException::ExtendsIsInvalidName, type, exceptionState);
            tryCatch.ReThrow();
            return false;
        }
        localName = type;
    }

    ASSERT(!tryCatch.HasCaught());
    tagName = QualifiedName(nullAtom, localName, namespaceURI);
    return true;
}
コード例 #12
0
void V8InjectedScriptHost::setNonEnumPropertyCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    if (info.Length() < 3 || !info[0]->IsObject() || !info[1]->IsString())
        return;

    v8::Local<v8::Object> object = info[0].As<v8::Object>();
    v8CallBoolean(object->DefineOwnProperty(info.GetIsolate()->GetCurrentContext(), info[1].As<v8::String>(), info[2], v8::DontEnum));
}
コード例 #13
0
bool toV8TestInterfaceEventInit(const TestInterfaceEventInit& impl, v8::Local<v8::Object> dictionary, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
{
    if (impl.hasStringMember()) {
        if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8String(isolate, "stringMember"), v8String(isolate, impl.stringMember()))))
            return false;
    }

    return true;
}
コード例 #14
0
ファイル: Dictionary.cpp プロジェクト: mirror/chromium
bool Dictionary::hasProperty(const StringView& key) const {
  v8::Local<v8::Object> object;
  if (!toObject(object))
    return false;

  DCHECK(m_isolate);
  DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent());
  return v8CallBoolean(object->Has(v8Context(), v8String(m_isolate, key)));
}
コード例 #15
0
ファイル: WebGLAny.cpp プロジェクト: mirror/chromium
ScriptValue WebGLAny(ScriptState* scriptState, const bool* value, size_t size) {
  v8::Local<v8::Array> array = v8::Array::New(scriptState->isolate(), size);
  for (size_t i = 0; i < size; ++i) {
    if (!v8CallBoolean(array->CreateDataProperty(
            scriptState->context(), i,
            v8Boolean(value[i], scriptState->isolate()))))
      return ScriptValue();
  }
  return ScriptValue(scriptState, array);
}
コード例 #16
0
ファイル: V8HiddenValue.cpp プロジェクト: mirror/chromium
bool V8HiddenValue::setHiddenValue(ScriptState* scriptState,
                                   v8::Local<v8::Object> object,
                                   v8::Local<v8::String> key,
                                   v8::Local<v8::Value> value) {
    if (UNLIKELY(value.IsEmpty()))
        return false;
    return v8CallBoolean(object->SetPrivate(
                             scriptState->context(), v8::Private::ForApi(scriptState->isolate(), key),
                             value));
}
コード例 #17
0
ファイル: V8HiddenValue.cpp プロジェクト: mirror/chromium
bool V8HiddenValue::deleteHiddenValue(ScriptState* scriptState,
                                      v8::Local<v8::Object> object,
                                      v8::Local<v8::String> key) {
    // Actually deleting the value would make force the object into dictionary
    // mode which is unnecessarily slow. Instead, we replace the hidden value with
    // "undefined".
    return v8CallBoolean(object->SetPrivate(
                             scriptState->context(), v8::Private::ForApi(scriptState->isolate(), key),
                             v8::Undefined(scriptState->isolate())));
}
コード例 #18
0
bool toV8TestPermissiveDictionary(const TestPermissiveDictionary& impl, v8::Local<v8::Object> dictionary, v8::Local<v8::Object> creationContext, v8::Isolate* isolate)
{
    // TODO(bashi): Use ForceSet() instead of Set(). http://crbug.com/476720
    if (impl.hasBooleanMember()) {
        if (!v8CallBoolean(dictionary->Set(isolate->GetCurrentContext(), v8String(isolate, "booleanMember"), v8Boolean(impl.booleanMember(), isolate))))
            return false;
    }

    return true;
}
コード例 #19
0
ファイル: WebGLAny.cpp プロジェクト: mirror/chromium
ScriptValue WebGLAny(ScriptState* scriptState, const Vector<int>& value) {
  size_t size = value.size();
  v8::Local<v8::Array> array = v8::Array::New(scriptState->isolate(), size);
  for (size_t i = 0; i < size; ++i) {
    if (!v8CallBoolean(array->CreateDataProperty(
            scriptState->context(), i,
            v8::Integer::New(scriptState->isolate(), value[i]))))
      return ScriptValue();
  }
  return ScriptValue(scriptState, array);
}
コード例 #20
0
ファイル: Dictionary.cpp プロジェクト: Tarnyko/chromium-blink
bool Dictionary::hasProperty(const String& key) const
{
    v8::Local<v8::Object> object;
    if (!toObject(object))
        return false;

    ASSERT(m_isolate);
    ASSERT(m_isolate == v8::Isolate::GetCurrent());
    ASSERT(m_exceptionState);
    v8::Local<v8::String> v8Key = v8String(m_isolate, key);
    return v8CallBoolean(object->Has(v8Context(), v8Key));
}
コード例 #21
0
ファイル: Dictionary.cpp プロジェクト: mirror/chromium
bool Dictionary::getInternal(const v8::Local<v8::Value>& key,
                             v8::Local<v8::Value>& result) const {
  v8::Local<v8::Object> object;
  if (!toObject(object))
    return false;

  DCHECK(m_isolate);
  DCHECK_EQ(m_isolate, v8::Isolate::GetCurrent());
  if (!v8CallBoolean(object->Has(v8Context(), key)))
    return false;
  return object->Get(v8Context(), key).ToLocal(&result);
}
コード例 #22
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));
}
コード例 #23
0
void V8TestInterfacePartial::preparePrototypeAndInterfaceObject(v8::Local<v8::Context> context, v8::Local<v8::Object> prototypeObject, v8::Local<v8::Function> interfaceObject, v8::Local<v8::FunctionTemplate> interfaceTemplate)
{
    V8TestInterface::preparePrototypeAndInterfaceObject(context, prototypeObject, interfaceObject, interfaceTemplate);
    v8::Isolate* isolate = context->GetIsolate();
    v8::Local<v8::Name> unscopablesSymbol(v8::Symbol::GetUnscopables(isolate));
    v8::Local<v8::Object> unscopeables;
    if (v8CallBoolean(prototypeObject->HasOwnProperty(context, unscopablesSymbol)))
        unscopeables = prototypeObject->Get(context, unscopablesSymbol).ToLocalChecked().As<v8::Object>();
    else
        unscopeables = v8::Object::New(isolate);
    unscopeables->CreateDataProperty(context, v8AtomicString(isolate, "unscopeableVoidMethod"), v8::True(isolate)).FromJust();
    prototypeObject->CreateDataProperty(context, unscopablesSymbol, unscopeables).FromJust();
}
コード例 #24
0
ファイル: WebBindings.cpp プロジェクト: dstockwell/blink
static NPObject* makeStringArrayImpl(const WebVector<WebString>& data, v8::Isolate* isolate)
{
    v8::HandleScope handleScope(isolate);
    v8::Local<v8::Array> result = v8::Array::New(isolate, data.size());
    for (size_t i = 0; i < data.size(); ++i) {
        if (!v8CallBoolean(result->Set(isolate->GetCurrentContext(), v8::Integer::New(isolate, i), v8String(isolate, data[i])))) {
            result.Clear();
            break;
        }
    }

    LocalDOMWindow* window = currentDOMWindow(isolate);
    return npCreateV8ScriptObject(isolate, 0, result, window);
}
コード例 #25
0
ファイル: V8HiddenValue.cpp プロジェクト: mirror/chromium
v8::Local<v8::Value> V8HiddenValue::getHiddenValue(ScriptState* scriptState,
        v8::Local<v8::Object> object,
        v8::Local<v8::String> key) {
    v8::Local<v8::Context> context = scriptState->context();
    v8::Local<v8::Private> privateKey =
        v8::Private::ForApi(scriptState->isolate(), key);
    v8::Local<v8::Value> value;
    // Callsites interpret an empty handle has absence of a result.
    if (!v8CallBoolean(object->HasPrivate(context, privateKey)))
        return v8::Local<v8::Value>();
    if (object->GetPrivate(context, privateKey).ToLocal(&value))
        return value;
    return v8::Local<v8::Value>();
}
コード例 #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);
}
コード例 #27
0
ファイル: Dictionary.cpp プロジェクト: Tarnyko/chromium-blink
bool Dictionary::getKey(const String& key, v8::Local<v8::Value>& value) const
{
    v8::Local<v8::Object> object;
    if (!toObject(object))
        return false;

    ASSERT(m_isolate);
    ASSERT(m_isolate == v8::Isolate::GetCurrent());
    ASSERT(m_exceptionState);
    v8::Local<v8::String> v8Key = v8String(m_isolate, key);
    if (!v8CallBoolean(object->Has(v8Context(), v8Key)))
        return false;
    return object->Get(v8Context(), v8Key).ToLocal(&value);
}
コード例 #28
0
ファイル: ImageData.cpp プロジェクト: dstockwell/blink
v8::Local<v8::Object> ImageData::associateWithWrapper(v8::Isolate* isolate, const WrapperTypeInfo* wrapperType, v8::Local<v8::Object> wrapper)
{
    wrapper = ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrapper);

    if (!wrapper.IsEmpty() && m_data.get()) {
        // Create a V8 Uint8ClampedArray object and set the "data" property
        // of the ImageData object to the created v8 object, eliminating the
        // C++ callback when accessing the "data" property.
        v8::Local<v8::Value> pixelArray = toV8(m_data.get(), wrapper, isolate);
        if (pixelArray.IsEmpty() || !v8CallBoolean(wrapper->DefineOwnProperty(isolate->GetCurrentContext(), v8AtomicString(isolate, "data"), pixelArray, v8::ReadOnly)))
            return v8::Local<v8::Object>();
    }
    return wrapper;
}
コード例 #29
0
ファイル: V8PerContextData.cpp プロジェクト: dstockwell/blink
v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(const WrapperTypeInfo* type)
{
    ASSERT(!m_errorPrototype.isEmpty());

    v8::Local<v8::Context> currentContext = context();
    v8::Context::Scope scope(currentContext);
    // We shouldn't reach this point for the types that are implemented in v8 such as typed arrays and
    // hence don't have domTemplateFunction.
    ASSERT(type->domTemplateFunction);
    v8::Local<v8::FunctionTemplate> functionTemplate = type->domTemplate(m_isolate);
    // Getting the function might fail if we're running out of stack or memory.
    v8::Local<v8::Function> function;
    if (!functionTemplate->GetFunction(currentContext).ToLocal(&function))
        return v8::Local<v8::Function>();

    if (type->parentClass) {
        v8::Local<v8::Object> prototypeTemplate = constructorForType(type->parentClass);
        if (prototypeTemplate.IsEmpty())
            return v8::Local<v8::Function>();
        if (!v8CallBoolean(function->SetPrototype(currentContext, prototypeTemplate)))
            return v8::Local<v8::Function>();
    }

    v8::Local<v8::Object> prototypeObject = function->Get(currentContext, v8AtomicString(m_isolate, "prototype")).ToLocalChecked().As<v8::Object>();
    if (prototypeObject->InternalFieldCount() == v8PrototypeInternalFieldcount
        && type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeObjectPrototype)
        prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeIndex, const_cast<WrapperTypeInfo*>(type));
    type->preparePrototypeObject(m_isolate, prototypeObject, functionTemplate);
    if (type->wrapperTypePrototype == WrapperTypeInfo::WrapperTypeExceptionPrototype) {
        if (!v8CallBoolean(prototypeObject->SetPrototype(currentContext, m_errorPrototype.newLocal(m_isolate))))
            return v8::Local<v8::Function>();
    }

    m_constructorMap.Set(type, function);

    return function;
}
コード例 #30
0
static void namedPropertyEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info)
{
    TestInterface2* impl = V8TestInterface2::toImpl(info.Holder());
    Vector<String> names;
    ExceptionState exceptionState(ExceptionState::EnumerationContext, "TestInterface2", info.Holder(), info.GetIsolate());
    impl->namedPropertyEnumerator(names, exceptionState);
    if (exceptionState.throwIfNeeded())
        return;
    v8::Local<v8::Array> v8names = v8::Array::New(info.GetIsolate(), names.size());
    for (size_t i = 0; i < names.size(); ++i) {
        if (!v8CallBoolean(v8names->CreateDataProperty(info.GetIsolate()->GetCurrentContext(), i, v8String(info.GetIsolate(), names[i]))))
            return;
    }
    v8SetReturnValue(info, v8names);
}