| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 #include "config.h" | 30 #include "config.h" |
| 31 #include "bindings/dart/DartHandleProxy.h" | 31 #include "bindings/dart/DartHandleProxy.h" |
| 32 | 32 |
| 33 #include "DartNode.h" | 33 #include "DartNode.h" |
| 34 #include "bindings/dart/DartScriptValue.h" | 34 #include "bindings/dart/DartScriptValue.h" |
| 35 #include "bindings/dart/DartUtilities.h" | |
| 36 #include "bindings/dart/V8Converter.h" | 35 #include "bindings/dart/V8Converter.h" |
| 37 #include "bindings/v8/PageScriptDebugServer.h" | 36 #include "bindings/v8/PageScriptDebugServer.h" |
| 38 #include "bindings/v8/ScriptController.h" | 37 #include "bindings/v8/ScriptController.h" |
| 39 #include "bindings/v8/ScriptState.h" | 38 #include "bindings/v8/ScriptState.h" |
| 40 #include "bindings/v8/V8Binding.h" | 39 #include "bindings/v8/V8Binding.h" |
| 41 #include "bindings/v8/V8ScriptRunner.h" | 40 #include "bindings/v8/V8ScriptRunner.h" |
| 42 #include "bindings/v8/V8ThrowException.h" | 41 #include "bindings/v8/V8ThrowException.h" |
| 43 | 42 |
| 44 #include "wtf/StdLibExtras.h" | 43 #include "wtf/StdLibExtras.h" |
| 45 | 44 |
| 46 #include <dart_debugger_api.h> | |
| 47 | |
| 48 namespace WebCore { | 45 namespace WebCore { |
| 49 | 46 |
| 50 typedef HashMap<String, v8::Persistent<v8::FunctionTemplate>* > FunctionTemplate
Map; | 47 typedef HashMap<String, v8::Persistent<v8::FunctionTemplate>* > FunctionTemplate
Map; |
| 51 | 48 |
| 52 static v8::Local<v8::FunctionTemplate> objectProxyTemplate(Dart_Handle instance)
; | 49 static v8::Local<v8::FunctionTemplate> objectProxyTemplate(Dart_Handle instance)
; |
| 53 static v8::Local<v8::FunctionTemplate> functionProxyTemplate(); | 50 static v8::Local<v8::FunctionTemplate> functionProxyTemplate(); |
| 54 static v8::Local<v8::FunctionTemplate> libraryProxyTemplate(); | 51 static v8::Local<v8::FunctionTemplate> libraryProxyTemplate(); |
| 55 static v8::Local<v8::FunctionTemplate> typeProxyTemplate(Dart_Handle type); | 52 static v8::Local<v8::FunctionTemplate> typeProxyTemplate(Dart_Handle type); |
| 56 static v8::Local<v8::FunctionTemplate> frameProxyTemplate(); | 53 static v8::Local<v8::FunctionTemplate> frameProxyTemplate(); |
| 57 | 54 |
| 58 DartScriptValue* readPointerFromProxy(v8::Handle<v8::Value> proxy) | 55 DartScriptValue* readPointerFromProxy(v8::Handle<v8::Value> proxy) |
| 59 { | 56 { |
| 60 void* pointer = proxy.As<v8::Object>()->GetAlignedPointerFromInternalField(0
); | 57 void* pointer = proxy.As<v8::Object>()->GetAlignedPointerFromInternalField(0
); |
| 61 return static_cast<DartScriptValue*>(pointer); | 58 return static_cast<DartScriptValue*>(pointer); |
| 62 } | 59 } |
| 63 | 60 |
| 64 /** | 61 DartScopes::DartScopes(v8::Local<v8::Object> v8Handle) : |
| 65 * Helper class to manage all scopes that must be entered to safely invoke Dart | 62 scriptValue(readPointerFromProxy(v8Handle)), |
| 66 * code. | 63 scope(scriptValue->isolate()) |
| 67 */ | 64 { |
| 68 class DartScopes { | 65 ASSERT(scriptValue->isIsolateAlive()); |
| 69 private: | 66 handle = Dart_HandleFromPersistent(scriptValue->value()); |
| 70 DartScriptValue* scriptValue; | 67 previousPauseInfo = Dart_GetExceptionPauseInfo(); |
| 71 DartIsolateScope scope; | 68 // FIXME: it is not clear this is the right long term solution but for |
| 72 DartApiScope apiScope; | 69 // now we prevent pausing on exceptions when executing Dart code to |
| 73 Dart_ExceptionPauseInfo previousPauseInfo; | 70 // avoid crashing when handling an exception triggers an exception. |
| 71 Dart_SetExceptionPauseInfo(kNoPauseOnExceptions); |
| 72 } |
| 74 | 73 |
| 75 public: | 74 DartScopes::~DartScopes() |
| 76 Dart_Handle handle; | 75 { |
| 76 Dart_SetExceptionPauseInfo(previousPauseInfo); |
| 77 } |
| 77 | 78 |
| 78 DartScopes(v8::Local<v8::Object> v8Handle) : | |
| 79 scriptValue(readPointerFromProxy(v8Handle)), | |
| 80 scope(scriptValue->isolate()) | |
| 81 { | |
| 82 ASSERT(scriptValue->isIsolateAlive()); | |
| 83 handle = Dart_HandleFromPersistent(scriptValue->value()); | |
| 84 previousPauseInfo = Dart_GetExceptionPauseInfo(); | |
| 85 // FIXME: it is not clear this is the right long term solution but for | |
| 86 // now we prevent pausing on exceptions when executing Dart code to | |
| 87 // avoid crashing when handling an exception triggers an exception. | |
| 88 Dart_SetExceptionPauseInfo(kNoPauseOnExceptions); | |
| 89 } | |
| 90 | |
| 91 ~DartScopes() | |
| 92 { | |
| 93 Dart_SetExceptionPauseInfo(previousPauseInfo); | |
| 94 } | |
| 95 }; | |
| 96 | 79 |
| 97 static void weakCallback(v8::Isolate* isolate, v8::Persistent<v8::Object>* proxy
, DartScriptValue* value) | 80 static void weakCallback(v8::Isolate* isolate, v8::Persistent<v8::Object>* proxy
, DartScriptValue* value) |
| 98 { | 81 { |
| 99 delete value; | 82 delete value; |
| 100 proxy->Dispose(isolate); | 83 proxy->Dispose(isolate); |
| 101 } | 84 } |
| 102 | 85 |
| 103 static Dart_Handle unwrapValue(v8::Handle<v8::Value> value) | 86 Dart_Handle DartHandleProxy::unwrapValue(v8::Handle<v8::Value> value) |
| 104 { | 87 { |
| 105 if (DartHandleProxy::isDartProxy(value)) | 88 if (DartHandleProxy::isDartProxy(value)) |
| 106 return Dart_HandleFromPersistent(readPointerFromProxy(value)->value()); | 89 return Dart_HandleFromPersistent(readPointerFromProxy(value)->value()); |
| 107 | 90 |
| 108 Dart_Handle exception = 0; | 91 Dart_Handle exception = 0; |
| 109 Dart_Handle handle = V8Converter::toDart(value, exception); | 92 Dart_Handle handle = V8Converter::toDart(value, exception); |
| 110 ASSERT(!exception); | 93 ASSERT(!exception); |
| 111 return handle; | 94 return handle; |
| 112 } | 95 } |
| 113 | 96 |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 bool isConstructor = false; | 323 bool isConstructor = false; |
| 341 Dart_FunctionIsConstructor(handle, &isConstructor); | 324 Dart_FunctionIsConstructor(handle, &isConstructor); |
| 342 if (args.IsConstructCall() != isConstructor) { | 325 if (args.IsConstructCall() != isConstructor) { |
| 343 V8ThrowException::throwError(v8::String::New( | 326 V8ThrowException::throwError(v8::String::New( |
| 344 isConstructor ? "Constructor called without new" : "Regular function
called as constructor")); | 327 isConstructor ? "Constructor called without new" : "Regular function
called as constructor")); |
| 345 return; | 328 return; |
| 346 } | 329 } |
| 347 | 330 |
| 348 Vector<Dart_Handle> dartFunctionArgs; | 331 Vector<Dart_Handle> dartFunctionArgs; |
| 349 for (uint32_t i = 0; i < args.Length(); ++i) | 332 for (uint32_t i = 0; i < args.Length(); ++i) |
| 350 dartFunctionArgs.append(unwrapValue(args[i])); | 333 dartFunctionArgs.append(DartHandleProxy::unwrapValue(args[i])); |
| 351 | 334 |
| 352 if (Dart_IsClosure(handle)) { | 335 if (Dart_IsClosure(handle)) { |
| 353 setReturnValue(args, Dart_InvokeClosure(handle, dartFunctionArgs.size(),
dartFunctionArgs.data())); | 336 setReturnValue(args, Dart_InvokeClosure(handle, dartFunctionArgs.size(),
dartFunctionArgs.data())); |
| 354 return; | 337 return; |
| 355 } | 338 } |
| 356 Dart_Handle type = Dart_FunctionOwner(handle); | 339 Dart_Handle type = Dart_FunctionOwner(handle); |
| 357 if (isConstructor) { | 340 if (isConstructor) { |
| 358 // FIXME: this seems like an overly complex way to have to invoke a cons
tructor. | 341 // FIXME: this seems like an overly complex way to have to invoke a cons
tructor. |
| 359 setReturnValue(args, | 342 setReturnValue(args, |
| 360 Dart_New(type, stripClassName(Dart_FunctionName(handle), Dart_ClassN
ame(type)), | 343 Dart_New(type, stripClassName(Dart_FunctionName(handle), Dart_ClassN
ame(type)), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 385 | 368 |
| 386 ASSERT(Dart_IsType(handle)); | 369 ASSERT(Dart_IsType(handle)); |
| 387 | 370 |
| 388 if (!args.IsConstructCall()) { | 371 if (!args.IsConstructCall()) { |
| 389 V8ThrowException::throwError(v8::String::New("Constructors can only be i
nvoked with 'new'")); | 372 V8ThrowException::throwError(v8::String::New("Constructors can only be i
nvoked with 'new'")); |
| 390 return; | 373 return; |
| 391 } | 374 } |
| 392 | 375 |
| 393 Vector<Dart_Handle> dartFunctionArgs; | 376 Vector<Dart_Handle> dartFunctionArgs; |
| 394 for (uint32_t i = 0; i < args.Length(); ++i) | 377 for (uint32_t i = 0; i < args.Length(); ++i) |
| 395 dartFunctionArgs.append(unwrapValue(args[i])); | 378 dartFunctionArgs.append(DartHandleProxy::unwrapValue(args[i])); |
| 396 | 379 |
| 397 setReturnValue(args, Dart_New(handle, Dart_Null(), dartFunctionArgs.size(),
dartFunctionArgs.data())); | 380 setReturnValue(args, Dart_New(handle, Dart_Null(), dartFunctionArgs.size(),
dartFunctionArgs.data())); |
| 398 } | 381 } |
| 399 | 382 |
| 400 void getImportedLibrariesMatchingPrefix(int32_t libraryId, Dart_Handle prefix, V
ector<std::pair<Dart_Handle, intptr_t> >* libraries) | 383 void getImportedLibrariesMatchingPrefix(int32_t libraryId, Dart_Handle prefix, V
ector<std::pair<Dart_Handle, intptr_t> >* libraries) |
| 401 { | 384 { |
| 402 Dart_Handle imports = Dart_GetLibraryImports(libraryId); | 385 Dart_Handle imports = Dart_GetLibraryImports(libraryId); |
| 403 ASSERT(!Dart_IsError(imports)); | 386 ASSERT(!Dart_IsError(imports)); |
| 404 // Unfortunately dart_debugger_api.h adds a trailing dot to import prefixes. | 387 // Unfortunately dart_debugger_api.h adds a trailing dot to import prefixes. |
| 405 if (!Dart_IsNull(prefix)) | 388 if (!Dart_IsNull(prefix)) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 // FIXME: we need to handle prefixes when setting library properties as well | 490 // FIXME: we need to handle prefixes when setting library properties as well |
| 508 // for completness. Postponing implementing this for now as we hope Dart_Invoke | 491 // for completness. Postponing implementing this for now as we hope Dart_Invoke |
| 509 // can just be fixed to handle libraries correctly. | 492 // can just be fixed to handle libraries correctly. |
| 510 static void libraryNamedPropertySetter(v8::Local<v8::String> property, v8::Local
<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 493 static void libraryNamedPropertySetter(v8::Local<v8::String> property, v8::Local
<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 511 { | 494 { |
| 512 DartScopes scopes(info.Holder()); | 495 DartScopes scopes(info.Holder()); |
| 513 Dart_Handle handle = scopes.handle; | 496 Dart_Handle handle = scopes.handle; |
| 514 | 497 |
| 515 Dart_Handle ret; | 498 Dart_Handle ret; |
| 516 ASSERT(Dart_IsLibrary(handle)); | 499 ASSERT(Dart_IsLibrary(handle)); |
| 517 Dart_Handle dartValue = unwrapValue(value); | 500 Dart_Handle dartValue = DartHandleProxy::unwrapValue(value); |
| 518 setReturnValue(info, Dart_SetField(handle, V8Converter::stringToDart(propert
y), dartValue)); | 501 setReturnValue(info, Dart_SetField(handle, V8Converter::stringToDart(propert
y), dartValue)); |
| 519 } | 502 } |
| 520 | 503 |
| 521 static void libraryQueryProperty(v8::Local<v8::String> name, const v8::PropertyC
allbackInfo<v8::Integer>& info) | 504 static void libraryQueryProperty(v8::Local<v8::String> name, const v8::PropertyC
allbackInfo<v8::Integer>& info) |
| 522 { | 505 { |
| 523 if (libraryNamedPropertyGetterHelper(name, info.Holder(), 0)) | 506 if (libraryNamedPropertyGetterHelper(name, info.Holder(), 0)) |
| 524 v8SetReturnValueInt(info, 0); | 507 v8SetReturnValueInt(info, 0); |
| 525 } | 508 } |
| 526 | 509 |
| 527 void libraryEnumerateHelper(Dart_Handle library, intptr_t libraryId, v8::Local<v
8::Array> properties, intptr_t* count) | 510 void libraryEnumerateHelper(Dart_Handle library, intptr_t libraryId, v8::Local<v
8::Array> properties, intptr_t* count) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 if (!Dart_IsNull(ret) && !Dart_IsError(ret)) | 611 if (!Dart_IsNull(ret) && !Dart_IsError(ret)) |
| 629 setReturnValue(info, ret); | 612 setReturnValue(info, ret); |
| 630 } | 613 } |
| 631 | 614 |
| 632 static void typeNamedPropertySetter(v8::Local<v8::String> property, v8::Local<v8
::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 615 static void typeNamedPropertySetter(v8::Local<v8::String> property, v8::Local<v8
::Value> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 633 { | 616 { |
| 634 DartScopes scopes(info.Holder()); | 617 DartScopes scopes(info.Holder()); |
| 635 Dart_Handle handle = scopes.handle; | 618 Dart_Handle handle = scopes.handle; |
| 636 | 619 |
| 637 ASSERT(Dart_IsType(handle)); | 620 ASSERT(Dart_IsType(handle)); |
| 638 Dart_Handle dartValue = unwrapValue(value); | 621 Dart_Handle dartValue = DartHandleProxy::unwrapValue(value); |
| 639 setReturnValue(info, Dart_Invoke(handle, V8Converter::stringToDart(v8::Strin
g::Concat(v8::String::New("set:"), property)), 1, &dartValue)); | 622 setReturnValue(info, Dart_Invoke(handle, V8Converter::stringToDart(v8::Strin
g::Concat(v8::String::New("set:"), property)), 1, &dartValue)); |
| 640 } | 623 } |
| 641 | 624 |
| 642 static void typeQueryProperty(v8::Local<v8::String> name, const v8::PropertyCall
backInfo<v8::Integer>& info) | 625 static void typeQueryProperty(v8::Local<v8::String> name, const v8::PropertyCall
backInfo<v8::Integer>& info) |
| 643 { | 626 { |
| 644 DartScopes scopes(info.Holder()); | 627 DartScopes scopes(info.Holder()); |
| 645 Dart_Handle handle = scopes.handle; | 628 Dart_Handle handle = scopes.handle; |
| 646 | 629 |
| 647 Dart_Handle ret; | 630 Dart_Handle ret; |
| 648 ASSERT(Dart_IsType(handle)); | 631 ASSERT(Dart_IsType(handle)); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 return; | 731 return; |
| 749 } | 732 } |
| 750 v8SetReturnValue(info, DartHandleProxy::create(result)); | 733 v8SetReturnValue(info, DartHandleProxy::create(result)); |
| 751 } | 734 } |
| 752 | 735 |
| 753 static void namedPropertySetter(v8::Local<v8::String> property, v8::Local<v8::Va
lue> value, const v8::PropertyCallbackInfo<v8::Value>& info) | 736 static void namedPropertySetter(v8::Local<v8::String> property, v8::Local<v8::Va
lue> value, const v8::PropertyCallbackInfo<v8::Value>& info) |
| 754 { | 737 { |
| 755 DartScopes scopes(info.Holder()); | 738 DartScopes scopes(info.Holder()); |
| 756 Dart_Handle handle = scopes.handle; | 739 Dart_Handle handle = scopes.handle; |
| 757 | 740 |
| 758 Dart_Handle dartValue = unwrapValue(value); | 741 Dart_Handle dartValue = DartHandleProxy::unwrapValue(value); |
| 759 setReturnValue(info, Dart_Invoke(handle, V8Converter::stringToDart(v8::Strin
g::Concat(v8::String::New("set:"), property)), 1, &dartValue)); | 742 setReturnValue(info, Dart_Invoke(handle, V8Converter::stringToDart(v8::Strin
g::Concat(v8::String::New("set:"), property)), 1, &dartValue)); |
| 760 } | 743 } |
| 761 | 744 |
| 762 static void objectQueryProperty(v8::Local<v8::String> name, const v8::PropertyCa
llbackInfo<v8::Integer>& info) | 745 static void objectQueryProperty(v8::Local<v8::String> name, const v8::PropertyCa
llbackInfo<v8::Integer>& info) |
| 763 { | 746 { |
| 764 DartScopes scopes(info.Holder()); | 747 DartScopes scopes(info.Holder()); |
| 765 Dart_Handle handle = scopes.handle; | 748 Dart_Handle handle = scopes.handle; |
| 766 | 749 |
| 767 Dart_Handle ret; | 750 Dart_Handle ret; |
| 768 ASSERT(Dart_IsInstance(handle)); | 751 ASSERT(Dart_IsInstance(handle)); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 setReturnValue(info, ret); | 827 setReturnValue(info, ret); |
| 845 } | 828 } |
| 846 | 829 |
| 847 static void indexedSetter(uint32_t index, v8::Local<v8::Value> value, const v8::
PropertyCallbackInfo<v8::Value>& info) | 830 static void indexedSetter(uint32_t index, v8::Local<v8::Value> value, const v8::
PropertyCallbackInfo<v8::Value>& info) |
| 848 { | 831 { |
| 849 DartScopes scopes(info.Holder()); | 832 DartScopes scopes(info.Holder()); |
| 850 Dart_Handle handle = scopes.handle; | 833 Dart_Handle handle = scopes.handle; |
| 851 | 834 |
| 852 Dart_Handle ret = 0; | 835 Dart_Handle ret = 0; |
| 853 if (Dart_IsList(handle)) | 836 if (Dart_IsList(handle)) |
| 854 ret = Dart_ListSetAt(handle, index, unwrapValue(value)); | 837 ret = Dart_ListSetAt(handle, index, DartHandleProxy::unwrapValue(value))
; |
| 855 else | 838 else |
| 856 ret = Dart_Null(); | 839 ret = Dart_Null(); |
| 857 | 840 |
| 858 setReturnValue(info, ret); | 841 setReturnValue(info, ret); |
| 859 } | 842 } |
| 860 | 843 |
| 861 static void indexedEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) | 844 static void indexedEnumerator(const v8::PropertyCallbackInfo<v8::Array>& info) |
| 862 { | 845 { |
| 863 DartScopes scopes(info.Holder()); | 846 DartScopes scopes(info.Holder()); |
| 864 Dart_Handle handle = scopes.handle; | 847 Dart_Handle handle = scopes.handle; |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 { | 1079 { |
| 1097 v8::Local<v8::Object> proxy = frameProxyTemplate()->InstanceTemplate()->NewI
nstance(); | 1080 v8::Local<v8::Object> proxy = frameProxyTemplate()->InstanceTemplate()->NewI
nstance(); |
| 1098 Dart_Handle localScopeVariableMap = createLocalVariablesMap(localVariables); | 1081 Dart_Handle localScopeVariableMap = createLocalVariablesMap(localVariables); |
| 1099 ASSERT(!Dart_IsError(localScopeVariableMap)); | 1082 ASSERT(!Dart_IsError(localScopeVariableMap)); |
| 1100 setDartHandleInternalField(proxy, localScopeVariableMap); | 1083 setDartHandleInternalField(proxy, localScopeVariableMap); |
| 1101 proxy->SetHiddenValue(v8::String::NewSymbol("dartProxy"), v8::Boolean::New(t
rue)); | 1084 proxy->SetHiddenValue(v8::String::NewSymbol("dartProxy"), v8::Boolean::New(t
rue)); |
| 1102 return proxy; | 1085 return proxy; |
| 1103 } | 1086 } |
| 1104 | 1087 |
| 1105 } | 1088 } |
| OLD | NEW |