Chromium Code Reviews| Index: Source/bindings/templates/interface.cpp |
| diff --git a/Source/bindings/templates/interface.cpp b/Source/bindings/templates/interface.cpp |
| index d26cbd2ef349ac23c4c48880e921b4a3e1d3dfd5..50b20f1c1daade5de5cbf02c3394a46bdd3c1bec 100644 |
| --- a/Source/bindings/templates/interface.cpp |
| +++ b/Source/bindings/templates/interface.cpp |
| @@ -746,11 +746,13 @@ V8DOMConfiguration::installAttribute({{method.function_template}}, v8::Handle<v8 |
| {##############################################################################} |
| {% block get_dom_template %} |
| +{% if is_v8object %} |
| v8::Handle<v8::FunctionTemplate> {{v8_class}}::domTemplate(v8::Isolate* isolate) |
| { |
| return V8DOMConfiguration::domClassTemplate(isolate, const_cast<WrapperTypeInfo*>(&wrapperTypeInfo), install{{v8_class}}Template); |
| } |
| +{% endif %} |
| {% endblock %} |
| @@ -758,14 +760,92 @@ v8::Handle<v8::FunctionTemplate> {{v8_class}}::domTemplate(v8::Isolate* isolate) |
| {% block has_instance %} |
| bool {{v8_class}}::hasInstance(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) |
| { |
| + {% if is_v8object %} |
| return V8PerIsolateData::from(isolate)->hasInstance(&wrapperTypeInfo, v8Value); |
| + {% else %} |
| + return v8Value->Is{{interface_name}}(); |
| + {% endif %} |
| } |
| +{% if is_v8object %} |
| v8::Handle<v8::Object> {{v8_class}}::findInstanceInPrototypeChain(v8::Handle<v8::Value> v8Value, v8::Isolate* isolate) |
| { |
| return V8PerIsolateData::from(isolate)->findInstanceInPrototypeChain(&wrapperTypeInfo, v8Value); |
| } |
| +{% endif %} |
| +{% endblock %} |
| + |
| + |
| +{##############################################################################} |
| +{% block to_impl %} |
| +{% if interface_name == 'ArrayBuffer' %} |
|
haraken
2014/10/14 15:11:18
Can we add a run-binding-test for ArrayBuffer inte
Yuki
2014/10/15 09:35:23
Will do.
|
| +DOMArrayBuffer* V8ArrayBuffer::toImpl(v8::Handle<v8::Object> object) |
| +{ |
| + ASSERT(object->IsArrayBuffer()); |
| + v8::Local<v8::ArrayBuffer> v8buffer = object.As<v8::ArrayBuffer>(); |
| + if (v8buffer->IsExternal()) { |
| + RELEASE_ASSERT(toWrapperTypeInfo(object)->ginEmbedder == gin::kEmbedderBlink); |
| + return blink::toScriptWrappableBase(object)->toImpl<DOMArrayBuffer>(); |
| + } |
| + |
| + v8::ArrayBuffer::Contents v8Contents = v8buffer->Externalize(); |
| + WTF::ArrayBufferContents contents(v8Contents.Data(), v8Contents.ByteLength(), 0); |
| + RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(contents); |
| + buffer->associateWithWrapper(buffer->wrapperTypeInfo(), object, v8::Isolate::GetCurrent()); |
| + |
| + return blink::toScriptWrappableBase(object)->toImpl<DOMArrayBuffer>(); |
| +} |
| +{% elif interface_name == 'ArrayBufferView' %} |
| +DOMArrayBufferView* V8ArrayBufferView::toImpl(v8::Handle<v8::Object> object) |
| +{ |
| + ASSERT(object->IsArrayBufferView()); |
| + ScriptWrappableBase* internalPointer = blink::toScriptWrappableBase(object); |
| + if (internalPointer) |
| + return internalPointer->toImpl<DOMArrayBufferView>(); |
| + |
| + if (object->IsInt8Array()) |
| + return V8Int8Array::toImpl(object); |
| + if (object->IsInt16Array()) |
| + return V8Int16Array::toImpl(object); |
| + if (object->IsInt32Array()) |
| + return V8Int32Array::toImpl(object); |
| + if (object->IsUint8Array()) |
| + return V8Uint8Array::toImpl(object); |
| + if (object->IsUint8ClampedArray()) |
| + return V8Uint8ClampedArray::toImpl(object); |
| + if (object->IsUint16Array()) |
| + return V8Uint16Array::toImpl(object); |
| + if (object->IsUint32Array()) |
| + return V8Uint32Array::toImpl(object); |
| + if (object->IsFloat32Array()) |
| + return V8Float32Array::toImpl(object); |
| + if (object->IsFloat64Array()) |
| + return V8Float64Array::toImpl(object); |
| + if (object->IsDataView()) |
| + return V8DataView::toImpl(object); |
| + |
| + ASSERT_NOT_REACHED(); |
| + return 0; |
| +} |
| +{% elif is_array_type %} |
| +{{cpp_class}}* {{v8_class}}::toImpl(v8::Handle<v8::Object> object) |
| +{ |
| + ASSERT(object->Is{{interface_name}}()); |
| + ScriptWrappableBase* internalPointer = blink::toScriptWrappableBase(object); |
| + if (internalPointer) |
|
haraken
2014/10/14 15:11:18
Just help me understand: In what scenario can the
Yuki
2014/10/15 09:35:23
There are cases that JS code (i.e. V8) creates an
|
| + return internalPointer->toImpl<{{cpp_class}}>(); |
| + |
| + v8::Handle<v8::{{interface_name}}> v8View = object.As<v8::{{interface_name}}>(); |
| + RefPtr<{{cpp_class}}> typedArray = {{cpp_class}}::create(V8ArrayBuffer::toImpl(v8View->Buffer()), v8View->ByteOffset(), v8View->{% if interface_name == 'DataView' %}Byte{% endif %}Length()); |
| + typedArray->associateWithWrapper(typedArray->wrapperTypeInfo(), object, v8::Isolate::GetCurrent()); |
|
haraken
2014/10/14 15:11:18
We should pass |isolate| to toImpl() and avoid cal
|
| + |
| + internalPointer = blink::toScriptWrappableBase(object); |
| + ASSERT(internalPointer); |
| + return internalPointer->toImpl<{{cpp_class}}>(); |
| +} |
| +{% endif %} |
| + |
| {% endblock %} |
| @@ -773,7 +853,7 @@ v8::Handle<v8::Object> {{v8_class}}::findInstanceInPrototypeChain(v8::Handle<v8: |
| {% block to_impl_with_type_check %} |
| {{cpp_class}}* {{v8_class}}::toImplWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value) |
| { |
| - return hasInstance(value, isolate) ? blink::toScriptWrappableBase(v8::Handle<v8::Object>::Cast(value))->toImpl<{{cpp_class}}>() : 0; |
| + return hasInstance(value, isolate) ? toImpl(v8::Handle<v8::Object>::Cast(value)) : 0; |
| } |
| {% endblock %} |
| @@ -781,7 +861,7 @@ v8::Handle<v8::Object> {{v8_class}}::findInstanceInPrototypeChain(v8::Handle<v8: |
| {##############################################################################} |
| {% block install_conditional_attributes %} |
| -{% if has_conditional_attributes %} |
| +{% if is_v8object and has_conditional_attributes %} |
| void {{v8_class}}::installConditionallyEnabledProperties(v8::Handle<v8::Object> instanceObject, v8::Isolate* isolate) |
| { |
| v8::Local<v8::Object> prototypeObject = v8::Local<v8::Object>::Cast(instanceObject->GetPrototype()); |
| @@ -804,7 +884,7 @@ void {{v8_class}}::installConditionallyEnabledProperties(v8::Handle<v8::Object> |
| {##############################################################################} |
| {% block install_conditional_methods %} |
| -{% if conditionally_enabled_methods %} |
| +{% if is_v8object and conditionally_enabled_methods %} |
| void {{v8_class}}::installConditionallyEnabledMethods(v8::Handle<v8::Object> prototypeObject, v8::Isolate* isolate) |
| { |
| {# Define per-context enabled operations #} |