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

Unified Diff: Source/bindings/core/dart/DartJsInterop.cpp

Issue 1908423004: Fix switching interceptor if element needs to upgraded after custom element is registered (Closed) Base URL: https://chromium.googlesource.com/dart/dartium/blink@2454_1
Patch Set: Created 4 years, 8 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/core/dart/DartJsInterop.cpp
diff --git a/Source/bindings/core/dart/DartJsInterop.cpp b/Source/bindings/core/dart/DartJsInterop.cpp
index 7d6498dc64925223ce02e25b1cf395316bb3d055..5f4037cd4397f7dcbd7f1dd34cae3c3784ba6803 100644
--- a/Source/bindings/core/dart/DartJsInterop.cpp
+++ b/Source/bindings/core/dart/DartJsInterop.cpp
@@ -1697,6 +1697,67 @@ fail:
ASSERT_NOT_REACHED();
}
+// Callback to force an instance to adopt a a specific custom element type.
+// Element accessed before custom class registerElement called. After which
+// each element with 'is' attribute custom type createdCallback is called with
+// the element to upgrade.
+static void setInstanceInterceptorCustomUpgradeCallback(Dart_NativeArguments args)
+{
+ Dart_Handle exception = 0;
+ {
+ DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateData(args));
+ auto v8Isolate = domData->v8Isolate();
+ v8::Local<v8::Context> context = domData->v8Context();
+ JsInteropScopes scopes(args, context);
+ JsObject* jsObject = toJsObject(args, 0, exception);
+ if (exception)
+ goto fail;
+ v8::Local<v8::Object> v8Object = jsObject->localV8Object(v8Isolate);
+ if (scopes.handleJsException(&exception))
+ goto fail;
+
+ // Get the type of the element (check to see if the interceptor is the
+ // CustomElementType).
+ Dart_Handle arg0 = Dart_GetNativeArgument(args, 0);
+ Dart_Handle dartType = Dart_InstanceGetType(arg0);
+ ASSERT(Dart_IsType(dartType));
+ ASSERT(!Dart_IsError(dartType));
+ Dart_Handle instanceType = Dart_TypeName(dartType);
+
+ // Get the interceptor
+ auto cache = domData->m_dartHandles.get(v8Object, v8Isolate);
+ InterceptorData* interceptor = jsObject->computeInterceptor(v8Object, domData, cache);
+
+ // Get the interceptor's custom element type.
+ Dart_Handle interceptorType = Dart_HandleFromPersistent(interceptor->m_type);
+ ASSERT(Dart_IsType(interceptorType));
+ ASSERT(!Dart_IsError(interceptorType));
+ Dart_Handle customType = Dart_TypeName(interceptorType);
+ ASSERT(Dart_IsType(customType));
+ ASSERT(!Dart_IsError(customType));
Jacob 2016/04/22 16:46:16 no need to have both the IsType and not IsError as
terry 2016/04/22 18:48:29 Yep, eliminated Dart_IsError.
+
+ bool equal;
Jacob 2016/04/22 16:46:16 For safety change to bool equal = false; as you ar
terry 2016/04/22 18:48:29 Done.
+ Dart_ObjectEquals(instanceType, customType, &equal);
+ if (!equal) {
+ // Type of the instance isn't the same as the custom element type so
+ // then we must change the interceptor. Upgrade to the registered
+ // element.
+ RELEASE_ASSERT(interceptor->m_isCustomElement);
+ cache->m_typedInterop = 0; // Clear existing handle.
+ scopes.setReturnValue(JsObject::createTyped(v8Object, domData, interceptor, cache));
+
+ if (scopes.handleJsException(&exception))
+ goto fail;
+ }
+ return;
+ }
+
+fail:
+ Dart_ThrowException(exception);
+ ASSERT_NOT_REACHED();
+}
+
+
static void callMethodCallbackHelper(Dart_NativeArguments args, bool legacy)
{
Dart_Handle exception = 0;
@@ -2386,6 +2447,7 @@ static DartNativeEntry nativeEntries[] = {
{ JsInteropInternal::defineInterceptorCustomElementCallback, 2, "Utils_defineInterceptorCustomElement" },
{ JsInteropInternal::defineInterceptorCallback, 2, "Utils_defineInterceptor" },
{ JsInteropInternal::setInstanceInterceptorCallback, 3, "Utils_setInstanceInterceptor" },
+ { JsInteropInternal::setInstanceInterceptorCustomUpgradeCallback, 1, "Utils_setInstanceInterceptorCustomUpgrade" },
{ JsInteropInternal::initializeCustomElement, 1, "Utils_initializeCustomElement" },
{ JsInteropInternal::toTypedObjectCallback, 1, "JSNative_toTypedObject" },
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698