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

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

Issue 10869063: Add attributions so printf like functions can have their arguments checked. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebased Created 8 years, 3 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/vm/dart_api_impl.h ('k') | 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) 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_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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 return Api::NewError("%s expects argument '%s' to be non-null.", \ 66 return Api::NewError("%s expects argument '%s' to be non-null.", \
67 CURRENT_FUNC, #parameter); 67 CURRENT_FUNC, #parameter);
68 68
69 69
70 #define CHECK_LENGTH(length, max_elements) \ 70 #define CHECK_LENGTH(length, max_elements) \
71 do { \ 71 do { \
72 intptr_t len = (length); \ 72 intptr_t len = (length); \
73 intptr_t max = (max_elements); \ 73 intptr_t max = (max_elements); \
74 if (len < 0 || len > max) { \ 74 if (len < 0 || len > max) { \
75 return Api::NewError( \ 75 return Api::NewError( \
76 "%s expects argument '%s' to be in the range [0..%ld].", \ 76 "%s expects argument '%s' to be in the range [0..%"Pd"].", \
77 CURRENT_FUNC, #length, max); \ 77 CURRENT_FUNC, #length, max); \
78 } \ 78 } \
79 } while (0) 79 } while (0)
80 80
81 81
82 // Return error if isolate is in an inconsistent state. 82 // Return error if isolate is in an inconsistent state.
83 // Return NULL when no error condition exists. 83 // Return NULL when no error condition exists.
84 // 84 //
85 // TODO(turnidge): Make this function return an error handle directly 85 // TODO(turnidge): Make this function return an error handle directly
86 // rather than returning an error string. The current behavior can 86 // rather than returning an error string. The current behavior can
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 DARTSCOPE(isolate); 834 DARTSCOPE(isolate);
835 TIMERSCOPE(time_creating_snapshot); 835 TIMERSCOPE(time_creating_snapshot);
836 if (buffer == NULL) { 836 if (buffer == NULL) {
837 RETURN_NULL_ERROR(buffer); 837 RETURN_NULL_ERROR(buffer);
838 } 838 }
839 if (size == NULL) { 839 if (size == NULL) {
840 RETURN_NULL_ERROR(size); 840 RETURN_NULL_ERROR(size);
841 } 841 }
842 const char* msg = CheckIsolateState(isolate); 842 const char* msg = CheckIsolateState(isolate);
843 if (msg != NULL) { 843 if (msg != NULL) {
844 return Api::NewError(msg); 844 return Api::NewError("%s", msg);
845 } 845 }
846 // Since this is only a snapshot the root library should not be set. 846 // Since this is only a snapshot the root library should not be set.
847 isolate->object_store()->set_root_library(Library::Handle(isolate)); 847 isolate->object_store()->set_root_library(Library::Handle(isolate));
848 FullSnapshotWriter writer(buffer, ApiReallocate); 848 FullSnapshotWriter writer(buffer, ApiReallocate);
849 writer.WriteFullSnapshot(); 849 writer.WriteFullSnapshot();
850 *size = writer.BytesWritten(); 850 *size = writer.BytesWritten();
851 return Api::Success(isolate); 851 return Api::Success(isolate);
852 } 852 }
853 853
854 854
855 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, 855 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer,
856 intptr_t* size) { 856 intptr_t* size) {
857 Isolate* isolate = Isolate::Current(); 857 Isolate* isolate = Isolate::Current();
858 DARTSCOPE(isolate); 858 DARTSCOPE(isolate);
859 TIMERSCOPE(time_creating_snapshot); 859 TIMERSCOPE(time_creating_snapshot);
860 if (buffer == NULL) { 860 if (buffer == NULL) {
861 RETURN_NULL_ERROR(buffer); 861 RETURN_NULL_ERROR(buffer);
862 } 862 }
863 if (size == NULL) { 863 if (size == NULL) {
864 RETURN_NULL_ERROR(size); 864 RETURN_NULL_ERROR(size);
865 } 865 }
866 const char* msg = CheckIsolateState(isolate); 866 const char* msg = CheckIsolateState(isolate);
867 if (msg != NULL) { 867 if (msg != NULL) {
868 return Api::NewError(msg); 868 return Api::NewError("%s", msg);
869 } 869 }
870 Library& library = 870 Library& library =
871 Library::Handle(isolate, isolate->object_store()->root_library()); 871 Library::Handle(isolate, isolate->object_store()->root_library());
872 if (library.IsNull()) { 872 if (library.IsNull()) {
873 return 873 return
874 Api::NewError("%s expects the isolate to have a script loaded in it.", 874 Api::NewError("%s expects the isolate to have a script loaded in it.",
875 CURRENT_FUNC); 875 CURRENT_FUNC);
876 } 876 }
877 ScriptSnapshotWriter writer(buffer, ApiReallocate); 877 ScriptSnapshotWriter writer(buffer, ApiReallocate);
878 writer.WriteScriptSnapshot(library); 878 writer.WriteScriptSnapshot(library);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 if (obj.IsError()) { 1180 if (obj.IsError()) {
1181 return object; 1181 return object;
1182 } else if (!obj.IsNull() && !obj.IsInstance()) { 1182 } else if (!obj.IsNull() && !obj.IsInstance()) {
1183 return Api::NewError( 1183 return Api::NewError(
1184 "%s expects argument 'object' to be an instance of Object.", 1184 "%s expects argument 'object' to be an instance of Object.",
1185 CURRENT_FUNC); 1185 CURRENT_FUNC);
1186 } 1186 }
1187 // Finalize all classes. 1187 // Finalize all classes.
1188 const char* msg = CheckIsolateState(isolate); 1188 const char* msg = CheckIsolateState(isolate);
1189 if (msg != NULL) { 1189 if (msg != NULL) {
1190 return Api::NewError(msg); 1190 return Api::NewError("%s", msg);
1191 } 1191 }
1192 if (obj.IsInstance()) { 1192 if (obj.IsInstance()) {
1193 const Type& type = Type::Handle(isolate, 1193 const Type& type = Type::Handle(isolate,
1194 Type::NewNonParameterizedType(cls)); 1194 Type::NewNonParameterizedType(cls));
1195 Error& malformed_type_error = Error::Handle(isolate); 1195 Error& malformed_type_error = Error::Handle(isolate);
1196 *value = Instance::Cast(obj).IsInstanceOf(type, 1196 *value = Instance::Cast(obj).IsInstanceOf(type,
1197 TypeArguments::Handle(isolate), 1197 TypeArguments::Handle(isolate),
1198 &malformed_type_error); 1198 &malformed_type_error);
1199 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. 1199 ASSERT(malformed_type_error.IsNull()); // Type was created from a class.
1200 } else { 1200 } else {
(...skipping 1272 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 Isolate* isolate = Isolate::Current(); 2473 Isolate* isolate = Isolate::Current();
2474 DARTSCOPE(isolate); 2474 DARTSCOPE(isolate);
2475 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 2475 const Class& cls = Api::UnwrapClassHandle(isolate, clazz);
2476 if (cls.IsNull()) { 2476 if (cls.IsNull()) {
2477 RETURN_TYPE_ERROR(isolate, clazz, Class); 2477 RETURN_TYPE_ERROR(isolate, clazz, Class);
2478 } 2478 }
2479 2479
2480 // Finalize all classes. 2480 // Finalize all classes.
2481 const char* msg = CheckIsolateState(isolate); 2481 const char* msg = CheckIsolateState(isolate);
2482 if (msg != NULL) { 2482 if (msg != NULL) {
2483 return Api::NewError(msg); 2483 return Api::NewError("%s", msg);
2484 } 2484 }
2485 2485
2486 if (cls.HasFactoryClass() && cls.HasResolvedFactoryClass()) { 2486 if (cls.HasFactoryClass() && cls.HasResolvedFactoryClass()) {
2487 return Api::NewHandle(isolate, cls.FactoryClass()); 2487 return Api::NewHandle(isolate, cls.FactoryClass());
2488 } 2488 }
2489 return Api::Null(isolate); 2489 return Api::Null(isolate);
2490 } 2490 }
2491 2491
2492 2492
2493 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceCount(Dart_Handle clazz, 2493 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceCount(Dart_Handle clazz,
(...skipping 20 matching lines...) Expand all
2514 Isolate* isolate = Isolate::Current(); 2514 Isolate* isolate = Isolate::Current();
2515 DARTSCOPE(isolate); 2515 DARTSCOPE(isolate);
2516 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 2516 const Class& cls = Api::UnwrapClassHandle(isolate, clazz);
2517 if (cls.IsNull()) { 2517 if (cls.IsNull()) {
2518 RETURN_TYPE_ERROR(isolate, clazz, Class); 2518 RETURN_TYPE_ERROR(isolate, clazz, Class);
2519 } 2519 }
2520 2520
2521 // Finalize all classes. 2521 // Finalize all classes.
2522 const char* msg = CheckIsolateState(isolate); 2522 const char* msg = CheckIsolateState(isolate);
2523 if (msg != NULL) { 2523 if (msg != NULL) {
2524 return Api::NewError(msg); 2524 return Api::NewError("%s", msg);
2525 } 2525 }
2526 2526
2527 const Array& interface_types = Array::Handle(isolate, cls.interfaces()); 2527 const Array& interface_types = Array::Handle(isolate, cls.interfaces());
2528 if (index < 0 || index >= interface_types.Length()) { 2528 if (index < 0 || index >= interface_types.Length()) {
2529 return Api::NewError("%s: argument 'index' out of bounds.", CURRENT_FUNC); 2529 return Api::NewError("%s: argument 'index' out of bounds.", CURRENT_FUNC);
2530 } 2530 }
2531 Type& interface_type = Type::Handle(isolate); 2531 Type& interface_type = Type::Handle(isolate);
2532 interface_type ^= interface_types.At(index); 2532 interface_type ^= interface_types.At(index);
2533 if (interface_type.HasResolvedTypeClass()) { 2533 if (interface_type.HasResolvedTypeClass()) {
2534 return Api::NewHandle(isolate, interface_type.type_class()); 2534 return Api::NewHandle(isolate, interface_type.type_class());
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
3053 if (name_obj.IsNull()) { 3053 if (name_obj.IsNull()) {
3054 dot_name = Symbols::Dot(); 3054 dot_name = Symbols::Dot();
3055 } else if (name_obj.IsString()) { 3055 } else if (name_obj.IsString()) {
3056 const String& dot = String::Handle(isolate, Symbols::Dot()); 3056 const String& dot = String::Handle(isolate, Symbols::Dot());
3057 dot_name = String::Concat(dot, String::Cast(name_obj)); 3057 dot_name = String::Concat(dot, String::Cast(name_obj));
3058 } else { 3058 } else {
3059 RETURN_TYPE_ERROR(isolate, constructor_name, String); 3059 RETURN_TYPE_ERROR(isolate, constructor_name, String);
3060 } 3060 }
3061 const char* msg = CheckIsolateState(isolate); 3061 const char* msg = CheckIsolateState(isolate);
3062 if (msg != NULL) { 3062 if (msg != NULL) {
3063 return Api::NewError(msg); 3063 return Api::NewError("%s", msg);
3064 } 3064 }
3065 3065
3066 // Check for interfaces with default implementations. 3066 // Check for interfaces with default implementations.
3067 if (cls.is_interface()) { 3067 if (cls.is_interface()) {
3068 // Make sure that the constructor is found in the interface. 3068 // Make sure that the constructor is found in the interface.
3069 result = ResolveConstructor( 3069 result = ResolveConstructor(
3070 "Dart_New", cls, base_constructor_name, dot_name, number_of_arguments); 3070 "Dart_New", cls, base_constructor_name, dot_name, number_of_arguments);
3071 if (result.IsError()) { 3071 if (result.IsError()) {
3072 return Api::NewHandle(isolate, result.raw()); 3072 return Api::NewHandle(isolate, result.raw());
3073 } 3073 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
3208 function_name.ToCString()); 3208 function_name.ToCString());
3209 } 3209 }
3210 return Api::NewHandle( 3210 return Api::NewHandle(
3211 isolate, 3211 isolate,
3212 DartEntry::InvokeDynamic(instance, function, args, kNoArgNames)); 3212 DartEntry::InvokeDynamic(instance, function, args, kNoArgNames));
3213 3213
3214 } else if (obj.IsClass()) { 3214 } else if (obj.IsClass()) {
3215 // Finalize all classes. 3215 // Finalize all classes.
3216 const char* msg = CheckIsolateState(isolate); 3216 const char* msg = CheckIsolateState(isolate);
3217 if (msg != NULL) { 3217 if (msg != NULL) {
3218 return Api::NewError(msg); 3218 return Api::NewError("%s", msg);
3219 } 3219 }
3220 3220
3221 const Class& cls = Class::Cast(obj); 3221 const Class& cls = Class::Cast(obj);
3222 const Function& function = Function::Handle( 3222 const Function& function = Function::Handle(
3223 isolate, 3223 isolate,
3224 Resolver::ResolveStatic(cls, 3224 Resolver::ResolveStatic(cls,
3225 function_name, 3225 function_name,
3226 number_of_arguments, 3226 number_of_arguments,
3227 Array::Handle(isolate), 3227 Array::Handle(isolate),
3228 Resolver::kIsQualified)); 3228 Resolver::kIsQualified));
(...skipping 18 matching lines...) Expand all
3247 Library& builtin = 3247 Library& builtin =
3248 Library::Handle(isolate, isolate->object_store()->builtin_library()); 3248 Library::Handle(isolate, isolate->object_store()->builtin_library());
3249 if (builtin.raw() == lib.raw()) { 3249 if (builtin.raw() == lib.raw()) {
3250 finalize_classes = false; 3250 finalize_classes = false;
3251 } 3251 }
3252 3252
3253 // Finalize all classes if needed. 3253 // Finalize all classes if needed.
3254 if (finalize_classes) { 3254 if (finalize_classes) {
3255 const char* msg = CheckIsolateState(isolate); 3255 const char* msg = CheckIsolateState(isolate);
3256 if (msg != NULL) { 3256 if (msg != NULL) {
3257 return Api::NewError(msg); 3257 return Api::NewError("%s", msg);
3258 } 3258 }
3259 } 3259 }
3260 3260
3261 Function& function = Function::Handle(isolate); 3261 Function& function = Function::Handle(isolate);
3262 function = lib.LookupFunctionAllowPrivate(function_name); 3262 function = lib.LookupFunctionAllowPrivate(function_name);
3263 if (function.IsNull()) { 3263 if (function.IsNull()) {
3264 return Api::NewError("%s: did not find top-level function '%s'.", 3264 return Api::NewError("%s: did not find top-level function '%s'.",
3265 CURRENT_FUNC, 3265 CURRENT_FUNC,
3266 function_name.ToCString()); 3266 function_name.ToCString());
3267 } 3267 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
3340 GrowableArray<const Object*> args; 3340 GrowableArray<const Object*> args;
3341 const Array& kNoArgNames = Array::Handle(isolate); 3341 const Array& kNoArgNames = Array::Handle(isolate);
3342 return Api::NewHandle( 3342 return Api::NewHandle(
3343 isolate, 3343 isolate,
3344 DartEntry::InvokeDynamic(instance, getter, args, kNoArgNames)); 3344 DartEntry::InvokeDynamic(instance, getter, args, kNoArgNames));
3345 3345
3346 } else if (obj.IsClass()) { 3346 } else if (obj.IsClass()) {
3347 // Finalize all classes. 3347 // Finalize all classes.
3348 const char* msg = CheckIsolateState(isolate); 3348 const char* msg = CheckIsolateState(isolate);
3349 if (msg != NULL) { 3349 if (msg != NULL) {
3350 return Api::NewError(msg); 3350 return Api::NewError("%s", msg);
3351 } 3351 }
3352 // To access a static field we may need to use the Field or the 3352 // To access a static field we may need to use the Field or the
3353 // getter Function. 3353 // getter Function.
3354 const Class& cls = Class::Cast(obj); 3354 const Class& cls = Class::Cast(obj);
3355 field = cls.LookupStaticField(field_name); 3355 field = cls.LookupStaticField(field_name);
3356 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { 3356 if (field.IsNull() || FieldIsUninitialized(isolate, field)) {
3357 const String& getter_name = 3357 const String& getter_name =
3358 String::Handle(isolate, Field::GetterName(field_name)); 3358 String::Handle(isolate, Field::GetterName(field_name));
3359 getter = cls.LookupStaticFunction(getter_name); 3359 getter = cls.LookupStaticFunction(getter_name);
3360 } 3360 }
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
3897 } 3897 }
3898 } 3898 }
3899 3899
3900 3900
3901 DART_EXPORT Dart_Handle Dart_CompileAll() { 3901 DART_EXPORT Dart_Handle Dart_CompileAll() {
3902 Isolate* isolate = Isolate::Current(); 3902 Isolate* isolate = Isolate::Current();
3903 DARTSCOPE(isolate); 3903 DARTSCOPE(isolate);
3904 Dart_Handle result; 3904 Dart_Handle result;
3905 const char* msg = CheckIsolateState(isolate); 3905 const char* msg = CheckIsolateState(isolate);
3906 if (msg != NULL) { 3906 if (msg != NULL) {
3907 return Api::NewError(msg); 3907 return Api::NewError("%s", msg);
3908 } 3908 }
3909 CompileAll(isolate, &result); 3909 CompileAll(isolate, &result);
3910 return result; 3910 return result;
3911 } 3911 }
3912 3912
3913 3913
3914 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { 3914 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) {
3915 return Api::ClassId(object) == kLibraryCid; 3915 return Api::ClassId(object) == kLibraryCid;
3916 } 3916 }
3917 3917
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
4048 // Propagate the error out right now. 4048 // Propagate the error out right now.
4049 if (::Dart_IsError(result)) { 4049 if (::Dart_IsError(result)) {
4050 return result; 4050 return result;
4051 } 4051 }
4052 4052
4053 // If this is the dart:builtin library, register it with the VM. 4053 // If this is the dart:builtin library, register it with the VM.
4054 if (url_str.Equals("dart:builtin")) { 4054 if (url_str.Equals("dart:builtin")) {
4055 isolate->object_store()->set_builtin_library(library); 4055 isolate->object_store()->set_builtin_library(library);
4056 const char* msg = CheckIsolateState(isolate); 4056 const char* msg = CheckIsolateState(isolate);
4057 if (msg != NULL) { 4057 if (msg != NULL) {
4058 return Api::NewError(msg); 4058 return Api::NewError("%s", msg);
4059 } 4059 }
4060 } 4060 }
4061 return result; 4061 return result;
4062 } 4062 }
4063 4063
4064 4064
4065 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, 4065 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library,
4066 Dart_Handle import, 4066 Dart_Handle import,
4067 Dart_Handle prefix) { 4067 Dart_Handle prefix) {
4068 Isolate* isolate = Isolate::Current(); 4068 Isolate* isolate = Isolate::Current();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
4179 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { 4179 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) {
4180 Dart::set_perf_events_writer(function); 4180 Dart::set_perf_events_writer(function);
4181 } 4181 }
4182 4182
4183 4183
4184 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { 4184 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) {
4185 Dart::set_flow_graph_writer(function); 4185 Dart::set_flow_graph_writer(function);
4186 } 4186 }
4187 4187
4188 } // namespace dart 4188 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698