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

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

Issue 1526123002: VM: Const-correctness fixes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/compiler.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 "include/dart_native_api.h" 5 #include "include/dart_native_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/bootstrap_natives.h" 7 #include "vm/bootstrap_natives.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart.h" 9 #include "vm/dart.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 return Object::null(); 250 return Object::null();
251 } 251 }
252 } 252 }
253 const String& msg = String::Handle(String::New( 253 const String& msg = String::Handle(String::New(
254 "Isolate.spawn expects to be passed a static or top-level function")); 254 "Isolate.spawn expects to be passed a static or top-level function"));
255 Exceptions::ThrowArgumentError(msg); 255 Exceptions::ThrowArgumentError(msg);
256 return Object::null(); 256 return Object::null();
257 } 257 }
258 258
259 259
260 static char* String2UTF8(const String& str) { 260 static const char* String2UTF8(const String& str) {
261 intptr_t len = Utf8::Length(str); 261 intptr_t len = Utf8::Length(str);
262 char* result = new char[len + 1]; 262 char* result = new char[len + 1];
263 str.ToUTF8(reinterpret_cast<uint8_t*>(result), len); 263 str.ToUTF8(reinterpret_cast<uint8_t*>(result), len);
264 result[len] = 0; 264 result[len] = 0;
265 265
266 return result; 266 return result;
267 } 267 }
268 268
269 269
270 static char* CanonicalizeUri(Thread* thread, 270 static const char* CanonicalizeUri(Thread* thread,
271 const Library& library, 271 const Library& library,
272 const String& uri, 272 const String& uri,
273 char** error) { 273 char** error) {
274 char* result = NULL; 274 const char* result = NULL;
275 Zone* zone = thread->zone(); 275 Zone* zone = thread->zone();
276 Isolate* isolate = thread->isolate(); 276 Isolate* isolate = thread->isolate();
277 Dart_LibraryTagHandler handler = isolate->library_tag_handler(); 277 Dart_LibraryTagHandler handler = isolate->library_tag_handler();
278 if (handler != NULL) { 278 if (handler != NULL) {
279 Dart_EnterScope(); 279 Dart_EnterScope();
280 Dart_Handle handle = handler(Dart_kCanonicalizeUrl, 280 Dart_Handle handle = handler(Dart_kCanonicalizeUrl,
281 Api::NewHandle(thread, library.raw()), 281 Api::NewHandle(thread, library.raw()),
282 Api::NewHandle(thread, uri.raw())); 282 Api::NewHandle(thread, uri.raw()));
283 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); 283 const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
284 if (obj.IsString()) { 284 if (obj.IsString()) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 args.SetAt(0, String::Handle(String::New( 327 args.SetAt(0, String::Handle(String::New(
328 "Isolate.spawnUri not supported under precompilation"))); 328 "Isolate.spawnUri not supported under precompilation")));
329 Exceptions::ThrowByType(Exceptions::kUnsupported, args); 329 Exceptions::ThrowByType(Exceptions::kUnsupported, args);
330 UNREACHABLE(); 330 UNREACHABLE();
331 } 331 }
332 332
333 // Canonicalize the uri with respect to the current isolate. 333 // Canonicalize the uri with respect to the current isolate.
334 const Library& root_lib = 334 const Library& root_lib =
335 Library::Handle(isolate->object_store()->root_library()); 335 Library::Handle(isolate->object_store()->root_library());
336 char* error = NULL; 336 char* error = NULL;
337 char* canonical_uri = CanonicalizeUri(thread, root_lib, uri, &error); 337 const char* canonical_uri = CanonicalizeUri(thread, root_lib, uri, &error);
338 if (canonical_uri == NULL) { 338 if (canonical_uri == NULL) {
339 const String& msg = String::Handle(String::New(error)); 339 const String& msg = String::Handle(String::New(error));
340 ThrowIsolateSpawnException(msg); 340 ThrowIsolateSpawnException(msg);
341 } 341 }
342 342
343 char* utf8_package_root = 343 const char* utf8_package_root =
344 package_root.IsNull() ? NULL : String2UTF8(package_root); 344 package_root.IsNull() ? NULL : String2UTF8(package_root);
345 345
346 char** utf8_package_map = NULL; 346 const char** utf8_package_map = NULL;
347 if (!packages.IsNull()) { 347 if (!packages.IsNull()) {
348 intptr_t len = packages.Length(); 348 intptr_t len = packages.Length();
349 utf8_package_map = new char*[len + 1]; 349 utf8_package_map = new const char*[len + 1];
350 350
351 Object& entry = Object::Handle(); 351 Object& entry = Object::Handle();
352 for (intptr_t i = 0; i < len; i++) { 352 for (intptr_t i = 0; i < len; i++) {
353 entry = packages.At(i); 353 entry = packages.At(i);
354 if (!entry.IsString()) { 354 if (!entry.IsString()) {
355 const String& msg = String::Handle(String::NewFormatted( 355 const String& msg = String::Handle(String::NewFormatted(
356 "Bad value in package map: %s", entry.ToCString())); 356 "Bad value in package map: %s", entry.ToCString()));
357 ThrowIsolateSpawnException(msg); 357 ThrowIsolateSpawnException(msg);
358 } 358 }
359 utf8_package_map[i] = String2UTF8(String::Cast(entry)); 359 utf8_package_map[i] = String2UTF8(String::Cast(entry));
360 } 360 }
361 // NULL terminated array. 361 // NULL terminated array.
362 utf8_package_map[len] = NULL; 362 utf8_package_map[len] = NULL;
363 } 363 }
364 364
365 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value(); 365 bool fatal_errors = fatalErrors.IsNull() ? true : fatalErrors.value();
366 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id(); 366 Dart_Port on_exit_port = onExit.IsNull() ? ILLEGAL_PORT : onExit.Id();
367 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id(); 367 Dart_Port on_error_port = onError.IsNull() ? ILLEGAL_PORT : onError.Id();
368 368
369 IsolateSpawnState* state = 369 IsolateSpawnState* state =
370 new IsolateSpawnState( 370 new IsolateSpawnState(
371 port.Id(), 371 port.Id(),
372 isolate->init_callback_data(), 372 isolate->init_callback_data(),
373 canonical_uri, 373 canonical_uri,
374 utf8_package_root, 374 utf8_package_root,
375 const_cast<const char**>(utf8_package_map), 375 utf8_package_map,
376 args, 376 args,
377 message, 377 message,
378 paused.value(), 378 paused.value(),
379 fatal_errors, 379 fatal_errors,
380 on_exit_port, 380 on_exit_port,
381 on_error_port); 381 on_error_port);
382 382
383 // If we were passed a value then override the default flags state for 383 // If we were passed a value then override the default flags state for
384 // checked mode. 384 // checked mode.
385 if (!checked.IsNull()) { 385 if (!checked.IsNull()) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 MessageWriter writer(&data, &allocator, false); 424 MessageWriter writer(&data, &allocator, false);
425 writer.WriteMessage(msg); 425 writer.WriteMessage(msg);
426 426
427 PortMap::PostMessage(new Message(port.Id(), 427 PortMap::PostMessage(new Message(port.Id(),
428 data, writer.BytesWritten(), 428 data, writer.BytesWritten(),
429 Message::kOOBPriority)); 429 Message::kOOBPriority));
430 return Object::null(); 430 return Object::null();
431 } 431 }
432 432
433 } // namespace dart 433 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698