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

Side by Side Diff: runtime/lib/isolate.cc

Issue 9316071: Dart_PropagateError, take 2. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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 | « runtime/include/dart_api.h ('k') | runtime/vm/ast.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/assert.h" 5 #include "platform/assert.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/dart.h" 8 #include "vm/dart.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 name ^= String::New(":"); 74 name ^= String::New(":");
75 str ^= String::Concat(str, name); 75 str ^= String::Concat(str, name);
76 name ^= String::NewSymbol(class_name); 76 name ^= String::NewSymbol(class_name);
77 str ^= String::Concat(str, name); 77 str ^= String::Concat(str, name);
78 GrowableArray<const Object*> arguments(1); 78 GrowableArray<const Object*> arguments(1);
79 arguments.Add(&str); 79 arguments.Add(&str);
80 Exceptions::ThrowByType(type, arguments); 80 Exceptions::ThrowByType(type, arguments);
81 } 81 }
82 82
83 83
84 RawInstance* ReceivePortCreate(intptr_t port_id) { 84 // TODO(turnidge): Move to DartLibraryCalls.
85 RawObject* ReceivePortCreate(intptr_t port_id) {
85 const String& class_name = 86 const String& class_name =
86 String::Handle(String::NewSymbol("ReceivePortImpl")); 87 String::Handle(String::NewSymbol("ReceivePortImpl"));
87 const String& function_name = 88 const String& function_name =
88 String::Handle(String::NewSymbol("_get_or_create")); 89 String::Handle(String::NewSymbol("_get_or_create"));
89 const int kNumArguments = 1; 90 const int kNumArguments = 1;
90 const Array& kNoArgumentNames = Array::Handle(); 91 const Array& kNoArgumentNames = Array::Handle();
91 const Function& function = Function::Handle( 92 const Function& function = Function::Handle(
92 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), 93 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()),
93 class_name, 94 class_name,
94 function_name, 95 function_name,
95 kNumArguments, 96 kNumArguments,
96 kNoArgumentNames, 97 kNoArgumentNames,
97 Resolver::kIsQualified)); 98 Resolver::kIsQualified));
98 GrowableArray<const Object*> arguments(kNumArguments); 99 GrowableArray<const Object*> arguments(kNumArguments);
99 arguments.Add(&Integer::Handle(Integer::New(port_id))); 100 arguments.Add(&Integer::Handle(Integer::New(port_id)));
100 const Instance& result = Instance::Handle( 101 const Object& result = Object::Handle(
101 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); 102 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames));
102 if (result.IsError()) { 103 if (!result.IsError()) {
103 ProcessError(result);
104 } else {
105 PortMap::SetLive(port_id); 104 PortMap::SetLive(port_id);
106 } 105 }
107 return result.raw(); 106 return result.raw();
108 } 107 }
109 108
110 109
111 static RawInstance* SendPortCreate(intptr_t port_id) { 110 // TODO(turnidge): Move to DartLibraryCalls.
111 static RawObject* SendPortCreate(intptr_t port_id) {
112 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl")); 112 const String& class_name = String::Handle(String::NewSymbol("SendPortImpl"));
113 const String& function_name = String::Handle(String::NewSymbol("_create")); 113 const String& function_name = String::Handle(String::NewSymbol("_create"));
114 const int kNumArguments = 1; 114 const int kNumArguments = 1;
115 const Array& kNoArgumentNames = Array::Handle(); 115 const Array& kNoArgumentNames = Array::Handle();
116 const Function& function = Function::Handle( 116 const Function& function = Function::Handle(
117 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()), 117 Resolver::ResolveStatic(Library::Handle(Library::CoreLibrary()),
118 class_name, 118 class_name,
119 function_name, 119 function_name,
120 kNumArguments, 120 kNumArguments,
121 kNoArgumentNames, 121 kNoArgumentNames,
122 Resolver::kIsQualified)); 122 Resolver::kIsQualified));
123 GrowableArray<const Object*> arguments(kNumArguments); 123 GrowableArray<const Object*> arguments(kNumArguments);
124 arguments.Add(&Integer::Handle(Integer::New(port_id))); 124 arguments.Add(&Integer::Handle(Integer::New(port_id)));
125 const Instance& result = Instance::Handle( 125 const Object& result = Object::Handle(
126 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); 126 DartEntry::InvokeStatic(function, arguments, kNoArgumentNames));
127 return result.raw(); 127 return result.raw();
128 } 128 }
129 129
130 130
131 static void RunIsolate(uword parameter) { 131 static void RunIsolate(uword parameter) {
132 IsolateStartData* data = reinterpret_cast<IsolateStartData*>(parameter); 132 IsolateStartData* data = reinterpret_cast<IsolateStartData*>(parameter);
133 Isolate* isolate = data->isolate_; 133 Isolate* isolate = data->isolate_;
134 char* library_url = data->library_url_; 134 char* library_url = data->library_url_;
135 char* class_name = data->class_name_; 135 char* class_name = data->class_name_;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 177 }
178 ASSERT(result.IsNull()); 178 ASSERT(result.IsNull());
179 } 179 }
180 180
181 // Invoke the "_run" method. 181 // Invoke the "_run" method.
182 const Function& target_function = Function::Handle(Resolver::ResolveDynamic( 182 const Function& target_function = Function::Handle(Resolver::ResolveDynamic(
183 target, String::Handle(String::NewSymbol("_run")), 2, 0)); 183 target, String::Handle(String::NewSymbol("_run")), 2, 0));
184 // TODO(iposva): Proper error checking here. 184 // TODO(iposva): Proper error checking here.
185 ASSERT(!target_function.IsNull()); 185 ASSERT(!target_function.IsNull());
186 // TODO(iposva): Allocate the proper port number here. 186 // TODO(iposva): Allocate the proper port number here.
187 const Instance& local_port = Instance::Handle(ReceivePortCreate(port_id)); 187 const Object& local_port = Object::Handle(ReceivePortCreate(port_id));
188 if (local_port.IsError()) {
189 ProcessError(local_port);
190 }
188 GrowableArray<const Object*> arguments(1); 191 GrowableArray<const Object*> arguments(1);
189 arguments.Add(&local_port); 192 arguments.Add(&local_port);
190 const Array& kNoArgumentNames = Array::Handle(); 193 const Array& kNoArgumentNames = Array::Handle();
191 result = DartEntry::InvokeDynamic(target, 194 result = DartEntry::InvokeDynamic(target,
192 target_function, 195 target_function,
193 arguments, 196 arguments,
194 kNoArgumentNames); 197 kNoArgumentNames);
195 if (result.IsError()) { 198 if (result.IsError()) {
196 ProcessError(result); 199 ProcessError(result);
197 } 200 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 326
324 // Switch back to the original isolate and return. 327 // Switch back to the original isolate and return.
325 Isolate::SetCurrent(preserved_isolate); 328 Isolate::SetCurrent(preserved_isolate);
326 if (spawned_isolate == NULL) { 329 if (spawned_isolate == NULL) {
327 // Unable to spawn isolate correctly, throw exception. 330 // Unable to spawn isolate correctly, throw exception.
328 ThrowErrorException(Exceptions::kIllegalArgument, 331 ThrowErrorException(Exceptions::kIllegalArgument,
329 error, 332 error,
330 library_url, 333 library_url,
331 class_name); 334 class_name);
332 } 335 }
333 const Instance& port = Instance::Handle(SendPortCreate(port_id)); 336
337 // TODO(turnidge): Move this code up before we launch the new
338 // thread. That way we won't have a thread hanging around that we
339 // can't talk to.
340 const Object& port = Object::Handle(SendPortCreate(port_id));
334 if (port.IsError()) { 341 if (port.IsError()) {
335 if (port.IsUnhandledException()) { 342 Exceptions::PropagateError(port);
336 ThrowErrorException(Exceptions::kInternalError,
337 "Unable to create send port to isolate",
338 library_url,
339 class_name);
340 } else {
341 ProcessError(port);
342 }
343 } 343 }
344 arguments->SetReturn(port); 344 arguments->SetReturn(port);
345 } 345 }
346 346
347 347
348 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) { 348 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) {
349 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); 349 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull());
350 intptr_t port_id = 350 intptr_t port_id =
351 PortMap::CreatePort(arguments->isolate()->message_handler()); 351 PortMap::CreatePort(arguments->isolate()->message_handler());
352 const Instance& port = Instance::Handle(ReceivePortCreate(port_id)); 352 const Object& port = Object::Handle(ReceivePortCreate(port_id));
353 if (port.IsError()) {
354 Exceptions::PropagateError(port);
355 }
353 arguments->SetReturn(port); 356 arguments->SetReturn(port);
354 } 357 }
355 358
356 359
357 DEFINE_NATIVE_ENTRY(ReceivePortImpl_closeInternal, 1) { 360 DEFINE_NATIVE_ENTRY(ReceivePortImpl_closeInternal, 1) {
358 intptr_t id = Smi::CheckedHandle(arguments->At(0)).Value(); 361 intptr_t id = Smi::CheckedHandle(arguments->At(0)).Value();
359 PortMap::ClosePort(id); 362 PortMap::ClosePort(id);
360 } 363 }
361 364
362 365
363 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { 366 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) {
364 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); 367 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value();
365 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); 368 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value();
366 // TODO(iposva): Allow for arbitrary messages to be sent. 369 // TODO(iposva): Allow for arbitrary messages to be sent.
367 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); 370 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2)));
368 371
369 // TODO(turnidge): Throw an exception when the return value is false? 372 // TODO(turnidge): Throw an exception when the return value is false?
370 PortMap::PostMessage(new Message( 373 PortMap::PostMessage(new Message(
371 send_id, reply_id, data, Message::kNormalPriority)); 374 send_id, reply_id, data, Message::kNormalPriority));
372 } 375 }
373 376
374 } // namespace dart 377 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698