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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 cache->m_typedInterop = 0; // Clear existing handle. 1690 cache->m_typedInterop = 0; // Clear existing handle.
1691 scopes.setReturnValue(JsObject::createTyped(v8Object, domData, &tempInte rceptor, cache)); 1691 scopes.setReturnValue(JsObject::createTyped(v8Object, domData, &tempInte rceptor, cache));
1692 return; 1692 return;
1693 } 1693 }
1694 1694
1695 fail: 1695 fail:
1696 Dart_ThrowException(exception); 1696 Dart_ThrowException(exception);
1697 ASSERT_NOT_REACHED(); 1697 ASSERT_NOT_REACHED();
1698 } 1698 }
1699 1699
1700 // Callback to force an instance to adopt a a specific custom element type.
1701 // Element accessed before custom class registerElement called. After which
1702 // each element with 'is' attribute custom type createdCallback is called with
1703 // the element to upgrade.
1704 static void setInstanceInterceptorCustomUpgradeCallback(Dart_NativeArguments arg s)
1705 {
1706 Dart_Handle exception = 0;
1707 {
1708 DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateDa ta(args));
1709 auto v8Isolate = domData->v8Isolate();
1710 v8::Local<v8::Context> context = domData->v8Context();
1711 JsInteropScopes scopes(args, context);
1712 JsObject* jsObject = toJsObject(args, 0, exception);
1713 if (exception)
1714 goto fail;
1715 v8::Local<v8::Object> v8Object = jsObject->localV8Object(v8Isolate);
1716 if (scopes.handleJsException(&exception))
1717 goto fail;
1718
1719 // Get the type of the element (check to see if the interceptor is the
1720 // CustomElementType).
1721 Dart_Handle arg0 = Dart_GetNativeArgument(args, 0);
1722 Dart_Handle dartType = Dart_InstanceGetType(arg0);
1723 ASSERT(Dart_IsType(dartType));
1724 ASSERT(!Dart_IsError(dartType));
1725 Dart_Handle instanceType = Dart_TypeName(dartType);
1726
1727 // Get the interceptor
1728 auto cache = domData->m_dartHandles.get(v8Object, v8Isolate);
1729 InterceptorData* interceptor = jsObject->computeInterceptor(v8Object, do mData, cache);
1730
1731 // Get the interceptor's custom element type.
1732 Dart_Handle interceptorType = Dart_HandleFromPersistent(interceptor->m_t ype);
1733 ASSERT(Dart_IsType(interceptorType));
1734 ASSERT(!Dart_IsError(interceptorType));
1735 Dart_Handle customType = Dart_TypeName(interceptorType);
1736 ASSERT(Dart_IsType(customType));
1737 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.
1738
1739 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.
1740 Dart_ObjectEquals(instanceType, customType, &equal);
1741 if (!equal) {
1742 // Type of the instance isn't the same as the custom element type so
1743 // then we must change the interceptor. Upgrade to the registered
1744 // element.
1745 RELEASE_ASSERT(interceptor->m_isCustomElement);
1746 cache->m_typedInterop = 0; // Clear existing handle.
1747 scopes.setReturnValue(JsObject::createTyped(v8Object, domData, interce ptor, cache));
1748
1749 if (scopes.handleJsException(&exception))
1750 goto fail;
1751 }
1752 return;
1753 }
1754
1755 fail:
1756 Dart_ThrowException(exception);
1757 ASSERT_NOT_REACHED();
1758 }
1759
1760
1700 static void callMethodCallbackHelper(Dart_NativeArguments args, bool legacy) 1761 static void callMethodCallbackHelper(Dart_NativeArguments args, bool legacy)
1701 { 1762 {
1702 Dart_Handle exception = 0; 1763 Dart_Handle exception = 0;
1703 { 1764 {
1704 DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateDa ta(args)); 1765 DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateDa ta(args));
1705 JsInteropScopes scopes(args, domData->v8Context()); 1766 JsInteropScopes scopes(args, domData->v8Context());
1706 auto v8Isolate = domData->v8Isolate(); 1767 auto v8Isolate = domData->v8Isolate();
1707 JsObject* receiver = DartDOMWrapper::receiver<JsObject>(args); 1768 JsObject* receiver = DartDOMWrapper::receiver<JsObject>(args);
1708 v8::Local<v8::Object> v8Receiver = receiver->localV8Object(v8Isolate); 1769 v8::Local<v8::Object> v8Receiver = receiver->localV8Object(v8Isolate);
1709 Dart_Handle name = Dart_GetNativeArgument(args, 1); 1770 Dart_Handle name = Dart_GetNativeArgument(args, 1);
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
2379 2440
2380 { JsInteropInternal::typedHashCodeCallback, 1, "JSObject_hashCode" }, 2441 { JsInteropInternal::typedHashCodeCallback, 1, "JSObject_hashCode" },
2381 { JsInteropInternal::typedCallMethodCallback, 3, "JSObject_callMethod" }, 2442 { JsInteropInternal::typedCallMethodCallback, 3, "JSObject_callMethod" },
2382 { JsInteropInternal::typedIndexGetter, 2, "JSArray_indexed_getter" }, 2443 { JsInteropInternal::typedIndexGetter, 2, "JSArray_indexed_getter" },
2383 { JsInteropInternal::typedIndexSetter, 3, "JSArray_indexed_setter" }, 2444 { JsInteropInternal::typedIndexSetter, 3, "JSArray_indexed_setter" },
2384 { JsInteropInternal::callConstructor0Callback, 1, "JSNative_callConstructor0 " }, 2445 { JsInteropInternal::callConstructor0Callback, 1, "JSNative_callConstructor0 " },
2385 { JsInteropInternal::callConstructorCallback, 2, "JSNative_callConstructor" }, 2446 { JsInteropInternal::callConstructorCallback, 2, "JSNative_callConstructor" },
2386 { JsInteropInternal::defineInterceptorCustomElementCallback, 2, "Utils_defin eInterceptorCustomElement" }, 2447 { JsInteropInternal::defineInterceptorCustomElementCallback, 2, "Utils_defin eInterceptorCustomElement" },
2387 { JsInteropInternal::defineInterceptorCallback, 2, "Utils_defineInterceptor" }, 2448 { JsInteropInternal::defineInterceptorCallback, 2, "Utils_defineInterceptor" },
2388 { JsInteropInternal::setInstanceInterceptorCallback, 3, "Utils_setInstanceIn terceptor" }, 2449 { JsInteropInternal::setInstanceInterceptorCallback, 3, "Utils_setInstanceIn terceptor" },
2450 { JsInteropInternal::setInstanceInterceptorCustomUpgradeCallback, 1, "Utils_ setInstanceInterceptorCustomUpgrade" },
2389 { JsInteropInternal::initializeCustomElement, 1, "Utils_initializeCustomElem ent" }, 2451 { JsInteropInternal::initializeCustomElement, 1, "Utils_initializeCustomElem ent" },
2390 2452
2391 { JsInteropInternal::toTypedObjectCallback, 1, "JSNative_toTypedObject" }, 2453 { JsInteropInternal::toTypedObjectCallback, 1, "JSNative_toTypedObject" },
2392 2454
2393 { JsInteropInternal::typedApplyCallback, 3, "JSFunction_apply" }, 2455 { JsInteropInternal::typedApplyCallback, 3, "JSFunction_apply" },
2394 { JsInteropInternal::typedFunctionCreateWithThisCallback, 1, "JSFunction_cre ateWithThis" }, 2456 { JsInteropInternal::typedFunctionCreateWithThisCallback, 1, "JSFunction_cre ateWithThis" },
2395 { JsInteropInternal::typedFunctionCreateCallback, 1, "JSFunction_create" }, 2457 { JsInteropInternal::typedFunctionCreateCallback, 1, "JSFunction_create" },
2396 2458
2397 // TODO(jacobr): do we want to do anything differently for JSObject 2459 // TODO(jacobr): do we want to do anything differently for JSObject
2398 // toString relative to JsObject.toString? 2460 // toString relative to JsObject.toString?
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
2793 2855
2794 proxyTemplateLocal->SetClassName(v8::String::NewFromUtf8(v8Isolate, "Dar tObject")); 2856 proxyTemplateLocal->SetClassName(v8::String::NewFromUtf8(v8Isolate, "Dar tObject"));
2795 setupInstanceTemplate(proxyTemplateLocal); 2857 setupInstanceTemplate(proxyTemplateLocal);
2796 } else { 2858 } else {
2797 proxyTemplateLocal = v8::Local<v8::FunctionTemplate>::New(v8Isolate, pro xyTemplate); 2859 proxyTemplateLocal = v8::Local<v8::FunctionTemplate>::New(v8Isolate, pro xyTemplate);
2798 } 2860 }
2799 return proxyTemplateLocal; 2861 return proxyTemplateLocal;
2800 } 2862 }
2801 2863
2802 } 2864 }
OLDNEW
« 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