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

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

Issue 8507035: Here's a template for how I plan on doing error-checking on inputs for (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
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl_test.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) 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"
11 #include "vm/dart_api_impl.h" 11 #include "vm/dart_api_impl.h"
12 #include "vm/dart_api_state.h" 12 #include "vm/dart_api_state.h"
13 #include "vm/dart_entry.h" 13 #include "vm/dart_entry.h"
14 #include "vm/debuginfo.h" 14 #include "vm/debuginfo.h"
15 #include "vm/exceptions.h" 15 #include "vm/exceptions.h"
16 #include "vm/growable_array.h" 16 #include "vm/growable_array.h"
17 #include "vm/longjump.h" 17 #include "vm/longjump.h"
18 #include "vm/native_entry.h" 18 #include "vm/native_entry.h"
19 #include "vm/object.h" 19 #include "vm/object.h"
20 #include "vm/object_store.h" 20 #include "vm/object_store.h"
21 #include "vm/port.h" 21 #include "vm/port.h"
22 #include "vm/resolver.h" 22 #include "vm/resolver.h"
23 #include "vm/snapshot.h" 23 #include "vm/snapshot.h"
24 #include "vm/stack_frame.h" 24 #include "vm/stack_frame.h"
25 #include "vm/timer.h" 25 #include "vm/timer.h"
26 #include "vm/verifier.h" 26 #include "vm/verifier.h"
27 27
28 namespace dart { 28 namespace dart {
29 29
30 #define UNWRAP_NONNULL(dart_handle, vm_handle, Type) \
31 do { \
32 const Object& tmp = Object::Handle(Api::UnwrapHandle((dart_handle))); \
33 if (tmp.Is##Type()) { \
34 (vm_handle) ^= tmp.raw(); \
35 } else if (tmp.IsNull()) { \
36 return Api::Error("%s expects argument '%s' to be non-null.", \
37 __func__, #dart_handle); \
38 } else if (tmp.IsApiFailure()) { \
39 return dart_handle; \
40 } else { \
41 return Api::Error("%s expects argument '%s' to be of type %s.", \
42 __func__, #dart_handle, #Type); \
43 } \
44 } while (0)
45
46
30 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) { 47 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) {
31 ASSERT(Isolate::Current() != NULL); 48 ASSERT(Isolate::Current() != NULL);
32 Zone zone; // Setup a VM zone as we are creating some handles. 49 Zone zone; // Setup a VM zone as we are creating some handles.
33 HandleScope scope; // Setup a VM handle scope. 50 HandleScope scope; // Setup a VM handle scope.
34 51
35 // Make sure that the object isn't an ApiFailure. 52 // Make sure that the object isn't an ApiFailure.
36 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); 53 const Object& obj = Object::Handle(Api::UnwrapHandle(handle));
37 return !obj.IsApiFailure(); 54 return !obj.IsApiFailure();
38 } 55 }
39 56
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 const Library& import = 391 const Library& import =
375 Library::CheckedHandle(Api::UnwrapHandle(import_in)); 392 Library::CheckedHandle(Api::UnwrapHandle(import_in));
376 library.AddImport(import); 393 library.AddImport(import);
377 return Api::Success(); 394 return Api::Success();
378 } 395 }
379 396
380 397
381 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { 398 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) {
382 Zone zone; // Setup a VM zone as we are creating some handles. 399 Zone zone; // Setup a VM zone as we are creating some handles.
383 HandleScope scope; // Setup a VM handle scope. 400 HandleScope scope; // Setup a VM handle scope.
384 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); 401 String& url_str = String::Handle();
402 UNWRAP_NONNULL(url, url_str, String);
385 const Library& library = Library::Handle(Library::LookupLibrary(url_str)); 403 const Library& library = Library::Handle(Library::LookupLibrary(url_str));
386 if (library.IsNull()) { 404 if (library.IsNull()) {
387 return Api::Error("Unknown library"); 405 return Api::Error("%s: library '%s' not found.",
406 __func__, url_str.ToCString());
388 } else { 407 } else {
389 return Api::NewLocalHandle(library); 408 return Api::NewLocalHandle(library);
390 } 409 }
391 } 410 }
392 411
393 412
394 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) { 413 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, Dart_Handle source) {
395 Zone zone; // Setup a VM zone as we are creating some handles. 414 Zone zone; // Setup a VM zone as we are creating some handles.
396 HandleScope scope; // Setup a VM handle scope. 415 HandleScope scope; // Setup a VM handle scope.
397 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url)); 416 const String& url_str = String::CheckedHandle(Api::UnwrapHandle(url));
(...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 ASSERT(state != NULL); 2041 ASSERT(state != NULL);
2023 PersistentHandle* true_handle = state->True(); 2042 PersistentHandle* true_handle = state->True();
2024 return reinterpret_cast<Dart_Handle>(true_handle); 2043 return reinterpret_cast<Dart_Handle>(true_handle);
2025 } 2044 }
2026 2045
2027 2046
2028 Dart_Handle Api::VError(const char* format, va_list args) { 2047 Dart_Handle Api::VError(const char* format, va_list args) {
2029 Zone zone; // Setup a VM zone as we are creating some handles. 2048 Zone zone; // Setup a VM zone as we are creating some handles.
2030 HandleScope scope; // Setup a VM handle scope. 2049 HandleScope scope; // Setup a VM handle scope.
2031 2050
2032 intptr_t len = OS::VSNPrint(NULL, 0, format, args); 2051 va_list args_copy;
2052 va_copy(args_copy, args);
2053 intptr_t len = OS::VSNPrint(NULL, 0, format, args_copy);
2054 va_end(args_copy);
2055
2033 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); 2056 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1));
2034 OS::VSNPrint(buffer, (len + 1), format, args); 2057 OS::VSNPrint(buffer, (len + 1), format, args);
2035 2058
2036 const String& message = String::Handle(String::New(buffer)); 2059 const String& message = String::Handle(String::New(buffer));
2037 const Object& obj = Object::Handle(ApiFailure::New(message)); 2060 const Object& obj = Object::Handle(ApiFailure::New(message));
2038 return Api::NewLocalHandle(obj); 2061 return Api::NewLocalHandle(obj);
2039 } 2062 }
2040 2063
2041
2042 Dart_Handle Api::Error(const char* format, ...) { 2064 Dart_Handle Api::Error(const char* format, ...) {
2043 va_list args; 2065 va_list args;
2044 va_start(args, format); 2066 va_start(args, format);
2045 Dart_Handle error = Api::VError(format, args); 2067 Dart_Handle error = Api::VError(format, args);
2046 va_end(args); 2068 va_end(args);
2047 return error; 2069 return error;
2048 } 2070 }
2049 2071
2050 2072
2051 Dart_Handle Api::Null() { 2073 Dart_Handle Api::Null() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 ASSERT(isolate != NULL); 2116 ASSERT(isolate != NULL);
2095 ApiState* state = isolate->api_state(); 2117 ApiState* state = isolate->api_state();
2096 ASSERT(state != NULL); 2118 ASSERT(state != NULL);
2097 ApiLocalScope* scope = state->top_scope(); 2119 ApiLocalScope* scope = state->top_scope();
2098 ASSERT(scope != NULL); 2120 ASSERT(scope != NULL);
2099 return scope->zone().Reallocate(ptr, old_size, new_size); 2121 return scope->zone().Reallocate(ptr, old_size, new_size);
2100 } 2122 }
2101 2123
2102 2124
2103 } // namespace dart 2125 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698