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

Side by Side Diff: Source/bindings/dart/DartHandleProxy.cpp

Issue 289083003: [dartium] Dart half of ScriptValue refactoring. (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/1916
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/dart/DartHandleProxy.h ('k') | Source/bindings/dart/DartJsInterop.cpp » ('j') | 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) 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
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/DartJsInterop.h" 34 #include "bindings/dart/DartJsInterop.h"
35 #include "bindings/dart/DartScriptValue.h" 35 #include "bindings/dart/DartPersistentValue.h"
36 #include "bindings/dart/V8Converter.h" 36 #include "bindings/dart/V8Converter.h"
37 #include "bindings/v8/PageScriptDebugServer.h" 37 #include "bindings/v8/PageScriptDebugServer.h"
38 #include "bindings/v8/ScriptController.h" 38 #include "bindings/v8/ScriptController.h"
39 #include "bindings/v8/ScriptState.h" 39 #include "bindings/v8/ScriptState.h"
40 #include "bindings/v8/V8Binding.h" 40 #include "bindings/v8/V8Binding.h"
41 #include "bindings/v8/V8ScriptRunner.h" 41 #include "bindings/v8/V8ScriptRunner.h"
42 #include "bindings/v8/V8ThrowException.h" 42 #include "bindings/v8/V8ThrowException.h"
43 43
44 #include "wtf/StdLibExtras.h" 44 #include "wtf/StdLibExtras.h"
45 45
46 namespace WebCore { 46 namespace WebCore {
47 47
48 struct DartHandleProxy::CallbackData { 48 struct DartHandleProxy::CallbackData {
49 ScopedPersistent<v8::Object> handle; 49 ScopedPersistent<v8::Object> handle;
50 DartScriptValue* value; 50 DartPersistentValue* value;
51 }; 51 };
52 52
53 typedef HashMap<String, v8::Persistent<v8::FunctionTemplate>* > FunctionTemplate Map; 53 typedef HashMap<String, v8::Persistent<v8::FunctionTemplate>* > FunctionTemplate Map;
54 54
55 static v8::Local<v8::FunctionTemplate> objectProxyTemplate(Dart_Handle instance) ; 55 static v8::Local<v8::FunctionTemplate> objectProxyTemplate(Dart_Handle instance) ;
56 static v8::Local<v8::FunctionTemplate> functionProxyTemplate(); 56 static v8::Local<v8::FunctionTemplate> functionProxyTemplate();
57 static v8::Local<v8::FunctionTemplate> libraryProxyTemplate(v8::Handle<v8::Strin g> libraryNameV8); 57 static v8::Local<v8::FunctionTemplate> libraryProxyTemplate(v8::Handle<v8::Strin g> libraryNameV8);
58 static v8::Local<v8::FunctionTemplate> typeProxyTemplate(Dart_Handle type); 58 static v8::Local<v8::FunctionTemplate> typeProxyTemplate(Dart_Handle type);
59 static v8::Local<v8::FunctionTemplate> frameProxyTemplate(); 59 static v8::Local<v8::FunctionTemplate> frameProxyTemplate();
60 60
61 DartScriptValue* DartHandleProxy::readPointerFromProxy(v8::Handle<v8::Value> pro xy) 61 DartPersistentValue* DartHandleProxy::readPointerFromProxy(v8::Handle<v8::Value> proxy)
62 { 62 {
63 void* pointer = proxy.As<v8::Object>()->GetAlignedPointerFromInternalField(0 ); 63 void* pointer = proxy.As<v8::Object>()->GetAlignedPointerFromInternalField(0 );
64 return static_cast<DartScriptValue*>(pointer); 64 return static_cast<DartPersistentValue*>(pointer);
65 } 65 }
66 66
67 bool DartHandleProxy::isDartProxy(v8::Handle<v8::Value> value) 67 bool DartHandleProxy::isDartProxy(v8::Handle<v8::Value> value)
68 { 68 {
69 if (value->IsObject()) { 69 if (value->IsObject()) {
70 v8::Isolate* v8Isolate = v8::Isolate::GetCurrent(); 70 v8::Isolate* v8Isolate = v8::Isolate::GetCurrent();
71 v8::Local<v8::Value> hiddenValue = value.As<v8::Object>()->GetHiddenValu e(v8::String::NewFromUtf8(v8Isolate, "dartProxy")); 71 v8::Local<v8::Value> hiddenValue = value.As<v8::Object>()->GetHiddenValu e(v8::String::NewFromUtf8(v8Isolate, "dartProxy"));
72 return *hiddenValue && hiddenValue->IsBoolean(); 72 return *hiddenValue && hiddenValue->IsBoolean();
73 } 73 }
74 return false; 74 return false;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 v8::Isolate* v8Isolate = v8::Isolate::GetCurrent(); 284 v8::Isolate* v8Isolate = v8::Isolate::GetCurrent();
285 V8ThrowException::throwError(v8::String::NewFromUtf8(v8Isolate, Dart_Get Error(result)), v8::Isolate::GetCurrent()); 285 V8ThrowException::throwError(v8::String::NewFromUtf8(v8Isolate, Dart_Get Error(result)), v8::Isolate::GetCurrent());
286 } else { 286 } else {
287 v8SetReturnValue(info, DartHandleProxy::create(result)); 287 v8SetReturnValue(info, DartHandleProxy::create(result));
288 } 288 }
289 } 289 }
290 290
291 void DartHandleProxy::writePointerToProxy(v8::Local<v8::Object> proxy, Dart_Hand le value) 291 void DartHandleProxy::writePointerToProxy(v8::Local<v8::Object> proxy, Dart_Hand le value)
292 { 292 {
293 ASSERT(!proxy.IsEmpty()); 293 ASSERT(!proxy.IsEmpty());
294 DartScriptValue* dartScriptValue = new DartScriptValue(value); 294 DartPersistentValue* dartScriptValue = new DartPersistentValue(value);
295 proxy->SetAlignedPointerInInternalField(0, dartScriptValue); 295 proxy->SetAlignedPointerInInternalField(0, dartScriptValue);
296 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 296 v8::Isolate* isolate = v8::Isolate::GetCurrent();
297 v8::Persistent<v8::Object> persistentHandle; 297 v8::Persistent<v8::Object> persistentHandle;
298 DartHandleProxy::CallbackData* callbackData = new DartHandleProxy::CallbackD ata(); 298 DartHandleProxy::CallbackData* callbackData = new DartHandleProxy::CallbackD ata();
299 callbackData->value = dartScriptValue; 299 callbackData->value = dartScriptValue;
300 callbackData->handle.set(isolate, proxy); 300 callbackData->handle.set(isolate, proxy);
301 callbackData->handle.setWeak(callbackData, &weakCallback); 301 callbackData->handle.setWeak(callbackData, &weakCallback);
302 } 302 }
303 303
304 intptr_t getLibraryId(v8::Local<v8::Object> proxy) 304 intptr_t getLibraryId(v8::Local<v8::Object> proxy)
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 } 1070 }
1071 1071
1072 /** 1072 /**
1073 * Returns the JavaScript type name following the Chrome debugger conventions 1073 * Returns the JavaScript type name following the Chrome debugger conventions
1074 * for Dart objects that have natural JavaScript analogs. 1074 * for Dart objects that have natural JavaScript analogs.
1075 * This enables visually consistent display of Dart Lists and JavaScript arrays, 1075 * This enables visually consistent display of Dart Lists and JavaScript arrays,
1076 * functions, and DOM nodes. 1076 * functions, and DOM nodes.
1077 */ 1077 */
1078 const char* DartHandleProxy::getJavaScriptType(v8::Handle<v8::Value> value) 1078 const char* DartHandleProxy::getJavaScriptType(v8::Handle<v8::Value> value)
1079 { 1079 {
1080 DartScriptValue* scriptValue = readPointerFromProxy(value); 1080 DartPersistentValue* scriptValue = readPointerFromProxy(value);
1081 ASSERT(scriptValue->isIsolateAlive()); 1081 ASSERT(scriptValue->isIsolateAlive());
1082 DartIsolateScope scope(scriptValue->isolate()); 1082 DartIsolateScope scope(scriptValue->isolate());
1083 DartApiScope apiScope; 1083 DartApiScope apiScope;
1084 Dart_PersistentHandle handle = scriptValue->value(); 1084 Dart_PersistentHandle handle = scriptValue->value();
1085 1085
1086 if (Dart_IsInstance(handle)) { 1086 if (Dart_IsInstance(handle)) {
1087 if (Dart_IsList(handle)) 1087 if (Dart_IsList(handle))
1088 return "array"; 1088 return "array";
1089 1089
1090 if (DartDOMWrapper::subtypeOf(handle, DartNode::dartClassId)) 1090 if (DartDOMWrapper::subtypeOf(handle, DartNode::dartClassId))
1091 return "node"; 1091 return "node";
1092 } 1092 }
1093 1093
1094 return 0; 1094 return 0;
1095 } 1095 }
1096 1096
1097 Node* DartHandleProxy::toNativeNode(v8::Handle<v8::Value> value) 1097 Node* DartHandleProxy::toNativeNode(v8::Handle<v8::Value> value)
1098 { 1098 {
1099 DartScriptValue* scriptValue = readPointerFromProxy(value); 1099 DartPersistentValue* scriptValue = readPointerFromProxy(value);
1100 ASSERT(scriptValue->isIsolateAlive()); 1100 ASSERT(scriptValue->isIsolateAlive());
1101 DartIsolateScope scope(scriptValue->isolate()); 1101 DartIsolateScope scope(scriptValue->isolate());
1102 DartApiScope apiScope; 1102 DartApiScope apiScope;
1103 Dart_PersistentHandle handle = scriptValue->value(); 1103 Dart_PersistentHandle handle = scriptValue->value();
1104 Dart_Handle exception = 0; 1104 Dart_Handle exception = 0;
1105 Node* node = DartNode::toNative(handle, exception); 1105 Node* node = DartNode::toNative(handle, exception);
1106 ASSERT(!exception); 1106 ASSERT(!exception);
1107 return node; 1107 return node;
1108 } 1108 }
1109 1109
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 for (intptr_t i = 0; i < length; i ++) 1237 for (intptr_t i = 0; i < length; i ++)
1238 dartFunctionArgs.append(Dart_ListGetAt(wrappedExpressionArgs, i)); 1238 dartFunctionArgs.append(Dart_ListGetAt(wrappedExpressionArgs, i));
1239 1239
1240 Dart_Handle result = Dart_InvokeClosure(closure, dartFunctionArgs.size(), da rtFunctionArgs.data()); 1240 Dart_Handle result = Dart_InvokeClosure(closure, dartFunctionArgs.size(), da rtFunctionArgs.data());
1241 if (Dart_IsError(result)) 1241 if (Dart_IsError(result))
1242 return V8ThrowException::throwError(v8::String::NewFromUtf8(v8Isolate, D art_GetError(result)), v8::Isolate::GetCurrent()); 1242 return V8ThrowException::throwError(v8::String::NewFromUtf8(v8Isolate, D art_GetError(result)), v8::Isolate::GetCurrent());
1243 return DartHandleProxy::create(result); 1243 return DartHandleProxy::create(result);
1244 } 1244 }
1245 1245
1246 } 1246 }
OLDNEW
« no previous file with comments | « Source/bindings/dart/DartHandleProxy.h ('k') | Source/bindings/dart/DartJsInterop.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698