Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Unified Diff: Source/bindings/dart/DartDOMWrapper.h

Issue 26789007: Add a native subtype of function that uses the native C++ class hierarchy to check if an element (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/dart/DartDOMData.h ('k') | Source/bindings/dart/DartLibraryIds.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/dart/DartDOMWrapper.h
===================================================================
--- Source/bindings/dart/DartDOMWrapper.h (revision 1437)
+++ Source/bindings/dart/DartDOMWrapper.h (working copy)
@@ -30,6 +30,8 @@
#ifndef DartDOMWrapper_h
#define DartDOMWrapper_h
+#include "DartWebkitClassIds.h"
+
#include "bindings/dart/DartDOMData.h"
#include "bindings/dart/DartExceptionState.h"
#include "bindings/dart/DartUtilities.h"
@@ -101,7 +103,7 @@
Dart_PersistentHandle type = dartClass(domData, className, libraryId, cid);
ASSERT(!Dart_IsError(type));
Dart_Handle wrapper = Dart_Allocate(type);
- writeNativePointer(wrapper, kNativeImplementationIndex, domObject);
+ writeNativePointer(wrapper, domObject, cid);
associateWrapper<BindingsClass>(domData, domObject, wrapper);
return wrapper;
}
@@ -142,14 +144,14 @@
if (Dart_IsNull(wrapper))
return 0;
- // FIXME: support cross-domain wrappers.
- if (!instanceOf<BindingsClass>(domData, wrapper)) {
- String message = String("Invalid class: expected instance of ") + BindingsClass::dartImplementationClassName;
- exception = DartUtilities::stringToDartString(message);
- return 0;
+ if (subtypeOf(wrapper, BindingsClass::dartClassId)) {
+ void* nativePointer = readNativePointer(wrapper, kNativeImplementationIndex);
+ return static_cast<typename BindingsClass::NativeType*>(nativePointer);
}
- void* nativePointer = readNativePointer(wrapper, kNativeImplementationIndex);
- return static_cast<typename BindingsClass::NativeType*>(nativePointer);
+ String message = String("Invalid class: expected instance of ") +
+ BindingsClass::dartImplementationClassName;
+ exception = DartUtilities::stringToDartString(message);
+ return 0;
}
template <class BindingsClass>
@@ -162,6 +164,19 @@
return unwrapDartWrapper<BindingsClass>(domData, wrapper, exception);
}
+ static bool subtypeOf(Dart_Handle wrapper, intptr_t basecid)
+ {
+ intptr_t cid = reinterpret_cast<intptr_t>(readNativePointer(wrapper, kNativeTypeIndex));
+ while (cid != -1) {
+ if (cid == basecid) {
+ return true;
+ }
+ ASSERT(cid < NumWebkitClassIds);
+ cid = DartWebkitClassInfo[cid].base_class_id;
+ }
+ return false;
+ }
+
template <class BindingsClass>
static bool instanceOf(DartDOMData* domData, Dart_Handle wrapper)
{
@@ -212,6 +227,7 @@
private:
enum NativeFieldIndices {
kNativeImplementationIndex = 0,
+ kNativeTypeIndex = 1,
kNativeFieldCount
};
@@ -232,12 +248,14 @@
static Dart_PersistentHandle dartClass(const char* dartImplementationClassName,
const char* dartImplementationLibraryName, intptr_t classIndex);
- static void writeNativePointer(Dart_Handle wrapper, int index, void* pointer)
+ static void writeNativePointer(Dart_Handle wrapper, void* pointer, intptr_t cid)
{
Dart_Handle result = Dart_SetNativeInstanceField(
- wrapper, index, reinterpret_cast<intptr_t>(pointer));
+ wrapper, kNativeImplementationIndex, reinterpret_cast<intptr_t>(pointer));
UNUSED_PARAM(result);
ASSERT(!Dart_IsError(result));
+ result = Dart_SetNativeInstanceField(wrapper, kNativeTypeIndex, cid);
+ ASSERT(!Dart_IsError(result));
}
static void* readNativePointer(Dart_Handle wrapper, int index)
« no previous file with comments | « Source/bindings/dart/DartDOMData.h ('k') | Source/bindings/dart/DartLibraryIds.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698