| OLD | NEW |
| 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 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 } | 752 } |
| 753 | 753 |
| 754 Dart_Handle JsObject::createTyped(v8::Local<v8::Object> object, DartDOMData* dom
Data, InterceptorData* interceptorData, InteropDartHandles* cache) | 754 Dart_Handle JsObject::createTyped(v8::Local<v8::Object> object, DartDOMData* dom
Data, InterceptorData* interceptorData, InteropDartHandles* cache) |
| 755 { | 755 { |
| 756 auto v8Isolate = domData->v8Isolate(); | 756 auto v8Isolate = domData->v8Isolate(); |
| 757 RefPtr<JsObject> jsObject = JsObject::create(object, v8Isolate); | 757 RefPtr<JsObject> jsObject = JsObject::create(object, v8Isolate); |
| 758 ASSERT(interceptorData->m_type); | 758 ASSERT(interceptorData->m_type); |
| 759 Dart_Handle wrapper = DartDOMWrapper::createWrapperForType<JsObject>(domData
, jsObject.get(), JsObject::dartClassId, interceptorData->m_type); | 759 Dart_Handle wrapper = DartDOMWrapper::createWrapperForType<JsObject>(domData
, jsObject.get(), JsObject::dartClassId, interceptorData->m_type); |
| 760 | 760 |
| 761 if (interceptorData->m_isCustomElement) { | 761 if (interceptorData->m_isCustomElement) { |
| 762 // Need to cache immediately in case we call back and forth between Dart
and JS. |
| 763 ASSERT(Dart_IsInstance(wrapper)); |
| 764 cache->m_typedInterop = Dart_NewPersistentHandle(wrapper); |
| 765 |
| 762 Dart_Handle ret = Dart_InvokeConstructor(wrapper, Dart_NewStringFromCStr
ing("created"), 0, 0); | 766 Dart_Handle ret = Dart_InvokeConstructor(wrapper, Dart_NewStringFromCStr
ing("created"), 0, 0); |
| 763 if (Dart_IsError(ret)) { | 767 if (Dart_IsError(ret)) { |
| 764 DartUtilities::reportProblem(domData->scriptExecutionContext(), ret)
; | 768 DartUtilities::reportProblem(domData->scriptExecutionContext(), ret)
; |
| 765 | 769 |
| 766 if (!domData->htmlElementType()) { | 770 if (!domData->htmlElementType()) { |
| 767 Dart_Handle htmlElementType = Dart_GetType(domData->htmlLibrary(
), Dart_NewStringFromCString("HtmlElementImpl"), 0, 0); | 771 Dart_Handle htmlElementType = Dart_GetType(domData->htmlLibrary(
), Dart_NewStringFromCString("HtmlElementImpl"), 0, 0); |
| 768 RELEASE_ASSERT(!Dart_IsError(htmlElementType)); | 772 RELEASE_ASSERT(!Dart_IsError(htmlElementType)); |
| 769 domData->setHtmlElementType(Dart_NewPersistentHandle(htmlElement
Type)); | 773 domData->setHtmlElementType(Dart_NewPersistentHandle(htmlElement
Type)); |
| 770 } | 774 } |
| 771 | 775 |
| 772 // We need a fresh JsObject to create a new DOM wrapper. | 776 // We need a fresh JsObject to create a new DOM wrapper. |
| 773 jsObject = JsObject::create(object, v8Isolate); | 777 jsObject = JsObject::create(object, v8Isolate); |
| 774 wrapper = DartDOMWrapper::createWrapperForType<JsObject>(domData, js
Object.get(), JsObject::dartClassId, domData->htmlElementType()); | 778 wrapper = DartDOMWrapper::createWrapperForType<JsObject>(domData, js
Object.get(), JsObject::dartClassId, domData->htmlElementType()); |
| 779 // Need to cache immediately in case we call back and forth between
Dart and JS. |
| 780 ASSERT(Dart_IsInstance(wrapper)); |
| 781 cache->m_typedInterop = Dart_NewPersistentHandle(wrapper); |
| 775 } | 782 } |
| 783 } else { |
| 784 // Simulate the behavior of the Dart dev compiler where new List() is |
| 785 // equivalent to a JavaScript array. We accomplish this by creating a |
| 786 // JavaScript object that fakes that it is a JavaScript array but is |
| 787 // actually backed by a Dart list. This is not a breaking change as |
| 788 // existing Dart-JS interop passed arrays as opaque Dart handles. |
| 789 // The jsify method can still be called if you wish to create a copy |
| 790 // of a json like Dart data structure. |
| 791 ASSERT(Dart_IsInstance(wrapper)); |
| 792 cache->m_typedInterop = Dart_NewPersistentHandle(wrapper); |
| 776 } | 793 } |
| 777 | |
| 778 ASSERT(Dart_IsInstance(wrapper)); | |
| 779 // Simulate the behavior of the Dart dev compiler where new List() is | |
| 780 // equivalent to a JavaScript array. We accomplish this by creating a | |
| 781 // JavaScript object that fakes that it is a JavaScript array but is | |
| 782 // actually backed by a Dart list. This is not a breaking change as | |
| 783 // existing Dart-JS interop passed arrays as opaque Dart handles. | |
| 784 // The jsify method can still be called if you wish to create a copy | |
| 785 // of a json like Dart data structure. | |
| 786 cache->m_typedInterop = Dart_NewPersistentHandle(wrapper); | |
| 787 return wrapper; | 794 return wrapper; |
| 788 } | 795 } |
| 789 | 796 |
| 790 void JsInterop::buildInteropPatchFiles(DartDOMData* domData, Vector<InteropPatch
File>* patches, Dart_Handle& exception) | 797 void JsInterop::buildInteropPatchFiles(DartDOMData* domData, Vector<InteropPatch
File>* patches, Dart_Handle& exception) |
| 791 { | 798 { |
| 792 // TODO(terry): startTime used for elapsed time perf debugging. | 799 // TODO(terry): startTime used for elapsed time perf debugging. |
| 793 double startTime = currentTimeMS(); | 800 double startTime = currentTimeMS(); |
| 794 ALLOW_UNUSED_LOCAL(startTime); | 801 ALLOW_UNUSED_LOCAL(startTime); |
| 795 | 802 |
| 796 Dart_Handle libraries = Dart_NewList(0); | 803 Dart_Handle libraries = Dart_NewList(0); |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 cache->m_typedInterop = 0; // Clear existing handle. | 1697 cache->m_typedInterop = 0; // Clear existing handle. |
| 1691 scopes.setReturnValue(JsObject::createTyped(v8Object, domData, &tempInte
rceptor, cache)); | 1698 scopes.setReturnValue(JsObject::createTyped(v8Object, domData, &tempInte
rceptor, cache)); |
| 1692 return; | 1699 return; |
| 1693 } | 1700 } |
| 1694 | 1701 |
| 1695 fail: | 1702 fail: |
| 1696 Dart_ThrowException(exception); | 1703 Dart_ThrowException(exception); |
| 1697 ASSERT_NOT_REACHED(); | 1704 ASSERT_NOT_REACHED(); |
| 1698 } | 1705 } |
| 1699 | 1706 |
| 1707 // Callback to force an instance to adopt a a specific custom element type. |
| 1708 // Element accessed before custom class registerElement called. After which |
| 1709 // each element with 'is' attribute custom type createdCallback is called with |
| 1710 // the element to upgrade. |
| 1711 static void setInstanceInterceptorCustomUpgradeCallback(Dart_NativeArguments arg
s) |
| 1712 { |
| 1713 Dart_Handle exception = 0; |
| 1714 { |
| 1715 DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateDa
ta(args)); |
| 1716 auto v8Isolate = domData->v8Isolate(); |
| 1717 v8::Local<v8::Context> context = domData->v8Context(); |
| 1718 JsInteropScopes scopes(args, context); |
| 1719 JsObject* jsObject = toJsObject(args, 0, exception); |
| 1720 if (exception) |
| 1721 goto fail; |
| 1722 v8::Local<v8::Object> v8Object = jsObject->localV8Object(v8Isolate); |
| 1723 if (scopes.handleJsException(&exception)) |
| 1724 goto fail; |
| 1725 |
| 1726 // Get the type of the element (check to see if the interceptor is the |
| 1727 // CustomElementType). |
| 1728 Dart_Handle arg0 = Dart_GetNativeArgument(args, 0); |
| 1729 Dart_Handle dartType = Dart_InstanceGetType(arg0); |
| 1730 ASSERT(Dart_IsType(dartType)); |
| 1731 Dart_Handle instanceType = Dart_TypeName(dartType); |
| 1732 |
| 1733 // Get the interceptor |
| 1734 auto cache = domData->m_dartHandles.get(v8Object, v8Isolate); |
| 1735 InterceptorData* interceptor = jsObject->computeInterceptor(v8Object, do
mData, cache); |
| 1736 |
| 1737 // Get the interceptor's custom element type. |
| 1738 Dart_Handle interceptorType = Dart_HandleFromPersistent(interceptor->m_t
ype); |
| 1739 ASSERT(Dart_IsType(interceptorType)); |
| 1740 Dart_Handle customType = Dart_TypeName(interceptorType); |
| 1741 ASSERT(Dart_IsType(customType)); |
| 1742 |
| 1743 bool equal = false; |
| 1744 Dart_ObjectEquals(instanceType, customType, &equal); |
| 1745 if (!equal) { |
| 1746 // Type of the instance isn't the same as the custom element type so |
| 1747 // then we must change the interceptor. Upgrade to the registered |
| 1748 // element. |
| 1749 RELEASE_ASSERT(interceptor->m_isCustomElement); |
| 1750 cache->m_typedInterop = 0; // Clear existing handle. |
| 1751 scopes.setReturnValue(JsObject::createTyped(v8Object, domData, interce
ptor, cache)); |
| 1752 |
| 1753 if (scopes.handleJsException(&exception)) |
| 1754 goto fail; |
| 1755 } |
| 1756 return; |
| 1757 } |
| 1758 |
| 1759 fail: |
| 1760 Dart_ThrowException(exception); |
| 1761 ASSERT_NOT_REACHED(); |
| 1762 } |
| 1763 |
| 1764 |
| 1700 static void callMethodCallbackHelper(Dart_NativeArguments args, bool legacy) | 1765 static void callMethodCallbackHelper(Dart_NativeArguments args, bool legacy) |
| 1701 { | 1766 { |
| 1702 Dart_Handle exception = 0; | 1767 Dart_Handle exception = 0; |
| 1703 { | 1768 { |
| 1704 DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateDa
ta(args)); | 1769 DartDOMData* domData = static_cast<DartDOMData*>(Dart_GetNativeIsolateDa
ta(args)); |
| 1705 JsInteropScopes scopes(args, domData->v8Context()); | 1770 JsInteropScopes scopes(args, domData->v8Context()); |
| 1706 auto v8Isolate = domData->v8Isolate(); | 1771 auto v8Isolate = domData->v8Isolate(); |
| 1707 JsObject* receiver = DartDOMWrapper::receiver<JsObject>(args); | 1772 JsObject* receiver = DartDOMWrapper::receiver<JsObject>(args); |
| 1708 v8::Local<v8::Object> v8Receiver = receiver->localV8Object(v8Isolate); | 1773 v8::Local<v8::Object> v8Receiver = receiver->localV8Object(v8Isolate); |
| 1709 Dart_Handle name = Dart_GetNativeArgument(args, 1); | 1774 Dart_Handle name = Dart_GetNativeArgument(args, 1); |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2379 | 2444 |
| 2380 { JsInteropInternal::typedHashCodeCallback, 1, "JSObject_hashCode" }, | 2445 { JsInteropInternal::typedHashCodeCallback, 1, "JSObject_hashCode" }, |
| 2381 { JsInteropInternal::typedCallMethodCallback, 3, "JSObject_callMethod" }, | 2446 { JsInteropInternal::typedCallMethodCallback, 3, "JSObject_callMethod" }, |
| 2382 { JsInteropInternal::typedIndexGetter, 2, "JSArray_indexed_getter" }, | 2447 { JsInteropInternal::typedIndexGetter, 2, "JSArray_indexed_getter" }, |
| 2383 { JsInteropInternal::typedIndexSetter, 3, "JSArray_indexed_setter" }, | 2448 { JsInteropInternal::typedIndexSetter, 3, "JSArray_indexed_setter" }, |
| 2384 { JsInteropInternal::callConstructor0Callback, 1, "JSNative_callConstructor0
" }, | 2449 { JsInteropInternal::callConstructor0Callback, 1, "JSNative_callConstructor0
" }, |
| 2385 { JsInteropInternal::callConstructorCallback, 2, "JSNative_callConstructor"
}, | 2450 { JsInteropInternal::callConstructorCallback, 2, "JSNative_callConstructor"
}, |
| 2386 { JsInteropInternal::defineInterceptorCustomElementCallback, 2, "Utils_defin
eInterceptorCustomElement" }, | 2451 { JsInteropInternal::defineInterceptorCustomElementCallback, 2, "Utils_defin
eInterceptorCustomElement" }, |
| 2387 { JsInteropInternal::defineInterceptorCallback, 2, "Utils_defineInterceptor"
}, | 2452 { JsInteropInternal::defineInterceptorCallback, 2, "Utils_defineInterceptor"
}, |
| 2388 { JsInteropInternal::setInstanceInterceptorCallback, 3, "Utils_setInstanceIn
terceptor" }, | 2453 { JsInteropInternal::setInstanceInterceptorCallback, 3, "Utils_setInstanceIn
terceptor" }, |
| 2454 { JsInteropInternal::setInstanceInterceptorCustomUpgradeCallback, 1, "Utils_
setInstanceInterceptorCustomUpgrade" }, |
| 2389 { JsInteropInternal::initializeCustomElement, 1, "Utils_initializeCustomElem
ent" }, | 2455 { JsInteropInternal::initializeCustomElement, 1, "Utils_initializeCustomElem
ent" }, |
| 2390 | 2456 |
| 2391 { JsInteropInternal::toTypedObjectCallback, 1, "JSNative_toTypedObject" }, | 2457 { JsInteropInternal::toTypedObjectCallback, 1, "JSNative_toTypedObject" }, |
| 2392 | 2458 |
| 2393 { JsInteropInternal::typedApplyCallback, 3, "JSFunction_apply" }, | 2459 { JsInteropInternal::typedApplyCallback, 3, "JSFunction_apply" }, |
| 2394 { JsInteropInternal::typedFunctionCreateWithThisCallback, 1, "JSFunction_cre
ateWithThis" }, | 2460 { JsInteropInternal::typedFunctionCreateWithThisCallback, 1, "JSFunction_cre
ateWithThis" }, |
| 2395 { JsInteropInternal::typedFunctionCreateCallback, 1, "JSFunction_create" }, | 2461 { JsInteropInternal::typedFunctionCreateCallback, 1, "JSFunction_create" }, |
| 2396 | 2462 |
| 2397 // TODO(jacobr): do we want to do anything differently for JSObject | 2463 // TODO(jacobr): do we want to do anything differently for JSObject |
| 2398 // toString relative to JsObject.toString? | 2464 // toString relative to JsObject.toString? |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2793 | 2859 |
| 2794 proxyTemplateLocal->SetClassName(v8::String::NewFromUtf8(v8Isolate, "Dar
tObject")); | 2860 proxyTemplateLocal->SetClassName(v8::String::NewFromUtf8(v8Isolate, "Dar
tObject")); |
| 2795 setupInstanceTemplate(proxyTemplateLocal); | 2861 setupInstanceTemplate(proxyTemplateLocal); |
| 2796 } else { | 2862 } else { |
| 2797 proxyTemplateLocal = v8::Local<v8::FunctionTemplate>::New(v8Isolate, pro
xyTemplate); | 2863 proxyTemplateLocal = v8::Local<v8::FunctionTemplate>::New(v8Isolate, pro
xyTemplate); |
| 2798 } | 2864 } |
| 2799 return proxyTemplateLocal; | 2865 return proxyTemplateLocal; |
| 2800 } | 2866 } |
| 2801 | 2867 |
| 2802 } | 2868 } |
| OLD | NEW |