bindings: Fixes custom versions of associateWithWrapper.

Fixes MessageEvent and ImageData's associateWithWrapper.  My first code in
http://crrev.com/542113003 assumed that associateWithWrapper was non-virtual
method, but it was changed to be virtual.  So I had to change the implementation
when and how to call associateWithWrapper from wrap (my first code assumed that
wrap calls the same class's associateWithWrapper because it was not virtual, but
since associateWithWrapper was changed to be virtual during the code review, now
wrap calls most derived class's associateWithWrapper).

BUG=413041,235436

Review URL: https://codereview.chromium.org/567063003

git-svn-id: svn://svn.chromium.org/blink/trunk@181983 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 40517c82
...@@ -187,20 +187,10 @@ void MessageEvent::trace(Visitor* visitor) ...@@ -187,20 +187,10 @@ void MessageEvent::trace(Visitor* visitor)
Event::trace(visitor); Event::trace(visitor);
} }
v8::Handle<v8::Object> MessageEvent::wrap(v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
v8::Handle<v8::Object> wrapper = Event::wrap(creationContext, isolate);
return associateWithWrapperInternal(wrapper, isolate);
}
v8::Handle<v8::Object> MessageEvent::associateWithWrapper(const WrapperTypeInfo* wrapperType, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate) v8::Handle<v8::Object> MessageEvent::associateWithWrapper(const WrapperTypeInfo* wrapperType, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate)
{ {
Event::associateWithWrapper(wrapperType, wrapper, isolate); Event::associateWithWrapper(wrapperType, wrapper, isolate);
return associateWithWrapperInternal(wrapper, isolate);
}
v8::Handle<v8::Object> MessageEvent::associateWithWrapperInternal(v8::Handle<v8::Object> wrapper, v8::Isolate* isolate)
{
// Ensures a wrapper is created for the data to return now so that V8 knows how // Ensures a wrapper is created for the data to return now so that V8 knows how
// much memory is used via the wrapper. To keep the wrapper alive, it's set to // much memory is used via the wrapper. To keep the wrapper alive, it's set to
// the wrapper of the MessageEvent as a hidden value. // the wrapper of the MessageEvent as a hidden value.
......
...@@ -115,7 +115,6 @@ public: ...@@ -115,7 +115,6 @@ public:
virtual void trace(Visitor*) OVERRIDE; virtual void trace(Visitor*) OVERRIDE;
virtual v8::Handle<v8::Object> wrap(v8::Handle<v8::Object> creationContext, v8::Isolate*) OVERRIDE;
virtual v8::Handle<v8::Object> associateWithWrapper(const WrapperTypeInfo*, v8::Handle<v8::Object> wrapper, v8::Isolate*) OVERRIDE; virtual v8::Handle<v8::Object> associateWithWrapper(const WrapperTypeInfo*, v8::Handle<v8::Object> wrapper, v8::Isolate*) OVERRIDE;
private: private:
...@@ -129,8 +128,6 @@ private: ...@@ -129,8 +128,6 @@ private:
MessageEvent(PassRefPtrWillBeRawPtr<Blob> data, const String& origin); MessageEvent(PassRefPtrWillBeRawPtr<Blob> data, const String& origin);
MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin); MessageEvent(PassRefPtr<ArrayBuffer> data, const String& origin);
v8::Handle<v8::Object> associateWithWrapperInternal(v8::Handle<v8::Object> wrapper, v8::Isolate*);
DataType m_dataType; DataType m_dataType;
RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue; RefPtr<SerializedScriptValue> m_dataAsSerializedScriptValue;
String m_dataAsString; String m_dataAsString;
......
...@@ -125,23 +125,13 @@ PassRefPtrWillBeRawPtr<ImageData> ImageData::create(Uint8ClampedArray* data, uns ...@@ -125,23 +125,13 @@ PassRefPtrWillBeRawPtr<ImageData> ImageData::create(Uint8ClampedArray* data, uns
return adoptRefWillBeNoop(new ImageData(IntSize(width, height), data)); return adoptRefWillBeNoop(new ImageData(IntSize(width, height), data));
} }
v8::Handle<v8::Object> ImageData::wrap(v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
v8::Handle<v8::Object> wrapper = ScriptWrappable::wrap(creationContext, isolate);
return associateWithWrapperInternal(wrapper, creationContext, isolate);
}
v8::Handle<v8::Object> ImageData::associateWithWrapper(const WrapperTypeInfo* wrapperType, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate) v8::Handle<v8::Object> ImageData::associateWithWrapper(const WrapperTypeInfo* wrapperType, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate)
{ {
ScriptWrappable::associateWithWrapper(wrapperType, wrapper, isolate); ScriptWrappable::associateWithWrapper(wrapperType, wrapper, isolate);
return associateWithWrapperInternal(wrapper, wrapper, isolate);
}
v8::Handle<v8::Object> ImageData::associateWithWrapperInternal(v8::Handle<v8::Object> wrapper, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
if (!wrapper.IsEmpty()) { if (!wrapper.IsEmpty()) {
// Create a V8 Uint8ClampedArray object. // Create a V8 Uint8ClampedArray object.
v8::Handle<v8::Value> pixelArray = toV8(data(), creationContext, isolate); v8::Handle<v8::Value> pixelArray = toV8(data(), wrapper, isolate);
// Set the "data" property of the ImageData object to // Set the "data" property of the ImageData object to
// the created v8 object, eliminating the C++ callback // the created v8 object, eliminating the C++ callback
// when accessing the "data" property. // when accessing the "data" property.
...@@ -164,4 +154,4 @@ ImageData::ImageData(const IntSize& size, PassRefPtr<Uint8ClampedArray> byteArra ...@@ -164,4 +154,4 @@ ImageData::ImageData(const IntSize& size, PassRefPtr<Uint8ClampedArray> byteArra
ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.height() * 4) <= m_data->length()); ASSERT_WITH_SECURITY_IMPLICATION(static_cast<unsigned>(size.width() * size.height() * 4) <= m_data->length());
} }
} } // namespace blink
...@@ -55,15 +55,12 @@ public: ...@@ -55,15 +55,12 @@ public:
void trace(Visitor*) { } void trace(Visitor*) { }
virtual v8::Handle<v8::Object> wrap(v8::Handle<v8::Object> creationContext, v8::Isolate*) OVERRIDE;
virtual v8::Handle<v8::Object> associateWithWrapper(const WrapperTypeInfo*, v8::Handle<v8::Object> wrapper, v8::Isolate*) OVERRIDE; virtual v8::Handle<v8::Object> associateWithWrapper(const WrapperTypeInfo*, v8::Handle<v8::Object> wrapper, v8::Isolate*) OVERRIDE;
private: private:
explicit ImageData(const IntSize&); explicit ImageData(const IntSize&);
ImageData(const IntSize&, PassRefPtr<Uint8ClampedArray>); ImageData(const IntSize&, PassRefPtr<Uint8ClampedArray>);
v8::Handle<v8::Object> associateWithWrapperInternal(v8::Handle<v8::Object> wrapper, v8::Handle<v8::Object> creationContext, v8::Isolate*);
IntSize m_size; IntSize m_size;
RefPtr<Uint8ClampedArray> m_data; RefPtr<Uint8ClampedArray> m_data;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment