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

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

Issue 9169102: Add Dart_PropagateError. (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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 323
321 // Switch back to the original isolate and return. 324 // Switch back to the original isolate and return.
322 Isolate::SetCurrent(preserved_isolate); 325 Isolate::SetCurrent(preserved_isolate);
323 if (spawned_isolate == NULL) { 326 if (spawned_isolate == NULL) {
324 // Unable to spawn isolate correctly, throw exception. 327 // Unable to spawn isolate correctly, throw exception.
325 ThrowErrorException(Exceptions::kIllegalArgument, 328 ThrowErrorException(Exceptions::kIllegalArgument,
326 error, 329 error,
327 library_url, 330 library_url,
328 class_name); 331 class_name);
329 } 332 }
330 const Instance& port = Instance::Handle(SendPortCreate(port_id)); 333
334 // TODO(turnidge): Move this code up before we launch the new
335 // thread. That way we won't have a thread hanging around that we
336 // can't talk to.
337 const Object& port = Object::Handle(SendPortCreate(port_id));
331 if (port.IsError()) { 338 if (port.IsError()) {
332 if (port.IsUnhandledException()) { 339 Exceptions::PropagateError(port);
333 ThrowErrorException(Exceptions::kInternalError,
334 "Unable to create send port to isolate",
335 library_url,
336 class_name);
337 } else {
338 ProcessError(port);
339 }
340 } 340 }
341 arguments->SetReturn(port); 341 arguments->SetReturn(port);
342 } 342 }
343 343
344 344
345 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) { 345 DEFINE_NATIVE_ENTRY(ReceivePortImpl_factory, 1) {
346 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); 346 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull());
347 intptr_t port_id = 347 intptr_t port_id =
348 PortMap::CreatePort(arguments->isolate()->message_handler()); 348 PortMap::CreatePort(arguments->isolate()->message_handler());
349 const Instance& port = Instance::Handle(ReceivePortCreate(port_id)); 349 const Object& port = Object::Handle(ReceivePortCreate(port_id));
350 if (port.IsError()) {
351 Exceptions::PropagateError(port);
352 }
350 arguments->SetReturn(port); 353 arguments->SetReturn(port);
351 } 354 }
352 355
353 356
354 DEFINE_NATIVE_ENTRY(ReceivePortImpl_closeInternal, 1) { 357 DEFINE_NATIVE_ENTRY(ReceivePortImpl_closeInternal, 1) {
355 intptr_t id = Smi::CheckedHandle(arguments->At(0)).Value(); 358 intptr_t id = Smi::CheckedHandle(arguments->At(0)).Value();
356 PortMap::ClosePort(id); 359 PortMap::ClosePort(id);
357 } 360 }
358 361
359 362
360 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) { 363 DEFINE_NATIVE_ENTRY(SendPortImpl_sendInternal_, 3) {
361 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value(); 364 intptr_t send_id = Smi::CheckedHandle(arguments->At(0)).Value();
362 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value(); 365 intptr_t reply_id = Smi::CheckedHandle(arguments->At(1)).Value();
363 // TODO(iposva): Allow for arbitrary messages to be sent. 366 // TODO(iposva): Allow for arbitrary messages to be sent.
364 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2))); 367 uint8_t* data = SerializeObject(Instance::CheckedHandle(arguments->At(2)));
365 368
366 // TODO(turnidge): Throw an exception when the return value is false? 369 // TODO(turnidge): Throw an exception when the return value is false?
367 PortMap::PostMessage(new Message( 370 PortMap::PostMessage(new Message(
368 send_id, reply_id, data, Message::kNormalPriority)); 371 send_id, reply_id, data, Message::kNormalPriority));
369 } 372 }
370 373
371 } // namespace dart 374 } // 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