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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 8528018: Start checking inputs to dart api functions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 308
309 309
310 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, 310 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url,
311 Dart_Handle source, 311 Dart_Handle source,
312 Dart_LibraryTagHandler handler) { 312 Dart_LibraryTagHandler handler) {
313 Isolate* isolate = Isolate::Current(); 313 Isolate* isolate = Isolate::Current();
314 ASSERT(isolate != NULL); 314 ASSERT(isolate != NULL);
315 Zone zone; // Setup a VM zone as we are creating some handles. 315 Zone zone; // Setup a VM zone as we are creating some handles.
316 HandleScope scope; // Setup a VM handle scope. 316 HandleScope scope; // Setup a VM handle scope.
317 TIMERSCOPE(time_script_loading); 317 TIMERSCOPE(time_script_loading);
318 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); 318 String& url_str = String::Handle();
319 const String& source_str = String::CheckedHandle(Api::UnwrapHandle(source)); 319 String& source_str = String::Handle();
320 UNWRAP_NONNULL(url, url_str, String);
321 UNWRAP_NONNULL(source, source_str, String);
siva 2011/11/15 22:09:49 This seems pretty hard to read in my opinion, the
turnidge 2011/11/15 23:30:42 Done.
320 Library& library = Library::Handle(isolate->object_store()->root_library()); 322 Library& library = Library::Handle(isolate->object_store()->root_library());
321 if (!library.IsNull()) { 323 if (!library.IsNull()) {
322 return Api::Error("Script already loaded"); 324 const String& library_url = String::Handle(library.url());
325 return Api::Error("%s: A script has already been loaded from '%s'.",
326 CURRENT_FUNC, library_url.ToCString());
323 } 327 }
324 isolate->set_library_tag_handler(handler); 328 isolate->set_library_tag_handler(handler);
325 library = Library::New(url_str); 329 library = Library::New(url_str);
326 library.Register(); 330 library.Register();
327 isolate->object_store()->set_root_library(library); 331 isolate->object_store()->set_root_library(library);
328 Dart_Handle result; 332 Dart_Handle result;
329 CompileSource(library, url_str, source_str, RawScript::kScript, &result); 333 CompileSource(library, url_str, source_str, RawScript::kScript, &result);
330 return result; 334 return result;
331 } 335 }
332 336
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 Zone zone; // Setup a VM zone as we are creating some handles. 390 Zone zone; // Setup a VM zone as we are creating some handles.
387 HandleScope scope; // Setup a VM handle scope. 391 HandleScope scope; // Setup a VM handle scope.
388 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 392 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
389 return obj.IsLibrary(); 393 return obj.IsLibrary();
390 } 394 }
391 395
392 396
393 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { 397 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) {
394 Zone zone; // Setup a VM zone as we are creating some handles. 398 Zone zone; // Setup a VM zone as we are creating some handles.
395 HandleScope scope; // Setup a VM handle scope. 399 HandleScope scope; // Setup a VM handle scope.
396 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); 400 Library& lib = Library::Handle();
397 if (lib.IsNull()) { 401 UNWRAP_NONNULL(library, lib, Library);
398 return Api::Error("Null library");
399 }
400 const String& url = String::Handle(lib.url()); 402 const String& url = String::Handle(lib.url());
401 ASSERT(!url.IsNull()); 403 ASSERT(!url.IsNull());
402 return Api::NewLocalHandle(url); 404 return Api::NewLocalHandle(url);
403 } 405 }
404 406
405 407
406 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library_in, 408 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library,
407 Dart_Handle import_in) { 409 Dart_Handle import) {
408 Zone zone; // Setup a VM zone as we are creating some handles. 410 Zone zone; // Setup a VM zone as we are creating some handles.
409 HandleScope scope; // Setup a VM handle scope. 411 HandleScope scope; // Setup a VM handle scope.
410 const Library& library = 412 Library& library_vm = Library::Handle();
411 Library::CheckedHandle(Api::UnwrapHandle(library_in)); 413 Library& import_vm = Library::Handle();
412 if (library.IsNull()) { 414 UNWRAP_NONNULL(library, library_vm, Library);
413 return Api::Error("Null library"); 415 UNWRAP_NONNULL(import, import_vm, Library);
414 } 416 library_vm.AddImport(import_vm);
415 const Library& import =
416 Library::CheckedHandle(Api::UnwrapHandle(import_in));
417 library.AddImport(import);
418 return Api::Success(); 417 return Api::Success();
419 } 418 }
420 419
421 420
422 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { 421 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) {
423 Zone zone; // Setup a VM zone as we are creating some handles. 422 Zone zone; // Setup a VM zone as we are creating some handles.
424 HandleScope scope; // Setup a VM handle scope. 423 HandleScope scope; // Setup a VM handle scope.
425 String& url_str = String::Handle(); 424 String& url_str = String::Handle();
426 UNWRAP_NONNULL(url, url_str, String); 425 UNWRAP_NONNULL(url, url_str, String);
427 const Library& library = Library::Handle(Library::LookupLibrary(url_str)); 426 const Library& library = Library::Handle(Library::LookupLibrary(url_str));
428 if (library.IsNull()) { 427 if (library.IsNull()) {
429 return Api::Error("%s: library '%s' not found.", 428 return Api::Error("%s: library '%s' not found.",
430 CURRENT_FUNC, url_str.ToCString()); 429 CURRENT_FUNC, url_str.ToCString());
431 } else { 430 } else {
432 return Api::NewLocalHandle(library); 431 return Api::NewLocalHandle(library);
433 } 432 }
434 } 433 }
435 434
436 435
437 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) { 436 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) {
438 Zone zone; // Setup a VM zone as we are creating some handles. 437 Zone zone; // Setup a VM zone as we are creating some handles.
439 HandleScope scope; // Setup a VM handle scope. 438 HandleScope scope; // Setup a VM handle scope.
440 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); 439 String& url_str = String::Handle();
441 const String& source_str = String::CheckedHandle(Api::UnwrapHandle(source)); 440 String& source_str = String::Handle();
441 UNWRAP_NONNULL(url, url_str, String);
442 UNWRAP_NONNULL(source, source_str, String);
442 Library& library = Library::Handle(Library::LookupLibrary(url_str)); 443 Library& library = Library::Handle(Library::LookupLibrary(url_str));
443 if (library.IsNull()) { 444 if (library.IsNull()) {
444 library = Library::New(url_str); 445 library = Library::New(url_str);
445 library.Register(); 446 library.Register();
447 } else if (library.name() != library.url()) {
siva 2011/11/15 22:09:49 This is not something that we can rely to check th
turnidge 2011/11/15 23:30:42 Ok. I'll wait for the fix. On 2011/11/15 22:09:4
turnidge 2011/11/18 00:50:15 Updated. On 2011/11/15 23:30:42, turnidge wrote:
448 // The source for this library has already been loaded.
449 return Api::Error("%s: library '%s' has already been loaded.",
450 CURRENT_FUNC, url_str.ToCString());
446 } 451 }
447 Dart_Handle result; 452 Dart_Handle result;
448 CompileSource(library, url_str, source_str, RawScript::kLibrary, &result); 453 CompileSource(library, url_str, source_str, RawScript::kLibrary, &result);
449 return result; 454 return result;
450 } 455 }
451 456
452 457
453 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library_in, 458 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library,
454 Dart_Handle url_in, 459 Dart_Handle url,
455 Dart_Handle source_in) { 460 Dart_Handle source) {
456 Zone zone; // Setup a VM zone as we are creating some handles. 461 Zone zone; // Setup a VM zone as we are creating some handles.
457 HandleScope scope; // Setup a VM handle scope. 462 HandleScope scope; // Setup a VM handle scope.
458 const String& url = String::CheckedHandle(Api::UnwrapHandle(url_in)); 463 Library& lib = Library::Handle();
459 const String& source = String::CheckedHandle(Api::UnwrapHandle(source_in)); 464 String& url_str = String::Handle();
460 const Library& library = 465 String& source_str = String::Handle();
461 Library::CheckedHandle(Api::UnwrapHandle(library_in)); 466 UNWRAP_NONNULL(library, lib, Library);
467 UNWRAP_NONNULL(url, url_str, String);
468 UNWRAP_NONNULL(source, source_str, String);
462 Dart_Handle result; 469 Dart_Handle result;
463 CompileSource(library, url, source, RawScript::kSource, &result); 470 CompileSource(lib, url_str, source_str, RawScript::kSource, &result);
464 return result; 471 return result;
465 } 472 }
466 473
467 474
468 DART_EXPORT Dart_Handle Dart_SetNativeResolver( 475 DART_EXPORT Dart_Handle Dart_SetNativeResolver(
469 Dart_Handle library, 476 Dart_Handle library,
470 Dart_NativeEntryResolver resolver) { 477 Dart_NativeEntryResolver resolver) {
471 Zone zone; // Setup a VM zone as we are creating some handles. 478 Zone zone; // Setup a VM zone as we are creating some handles.
472 HandleScope scope; // Setup a VM handle scope. 479 HandleScope scope; // Setup a VM handle scope.
473 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); 480 Library& lib = Library::Handle();
474 if (lib.IsNull()) { 481 UNWRAP_NONNULL(library, lib, Library);
475 return Api::Error("Invalid parameter, Unknown library specified");
476 }
477 lib.set_native_entry_resolver(resolver); 482 lib.set_native_entry_resolver(resolver);
478 return Api::Success(); 483 return Api::Success();
479 } 484 }
480 485
481 486
482 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { 487 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) {
483 Zone zone; // Setup a VM zone as we are creating some handles. 488 Zone zone; // Setup a VM zone as we are creating some handles.
484 HandleScope scope; // Setup a VM handle scope. 489 HandleScope scope; // Setup a VM handle scope.
485 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 490 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
486 Object& result = Object::Handle(); 491 Object& result = Object::Handle();
(...skipping 1648 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 ASSERT(isolate != NULL); 2140 ASSERT(isolate != NULL);
2136 ApiState* state = isolate->api_state(); 2141 ApiState* state = isolate->api_state();
2137 ASSERT(state != NULL); 2142 ASSERT(state != NULL);
2138 ApiLocalScope* scope = state->top_scope(); 2143 ApiLocalScope* scope = state->top_scope();
2139 ASSERT(scope != NULL); 2144 ASSERT(scope != NULL);
2140 return scope->zone().Reallocate(ptr, old_size, new_size); 2145 return scope->zone().Reallocate(ptr, old_size, new_size);
2141 } 2146 }
2142 2147
2143 2148
2144 } // namespace dart 2149 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698