Chromium Code Reviews| Index: bin/builtin_natives.cc |
| =================================================================== |
| --- bin/builtin_natives.cc (revision 1771) |
| +++ bin/builtin_natives.cc (working copy) |
| @@ -10,15 +10,7 @@ |
| #include "bin/builtin.h" |
| #include "bin/dartutils.h" |
| -// The string on the next line will be filled in with the contents of the |
| -// builtin.dart file. |
| -// This string forms the content of builtin functionality which is injected |
| -// into standalone dart to provide some test/debug functionality. |
| -static const char Builtin_source_[] = { |
| - {{DART_SOURCE}} |
| -}; |
| - |
| // List all native functions implemented in standalone dart that is used |
| // to inject additional functionality e.g: Logger, file I/O, socket I/O etc. |
| #define BUILTIN_NATIVE_LIST(V) \ |
| @@ -40,6 +32,7 @@ |
| V(File_WriteList, 4) \ |
| V(File_Position, 1) \ |
| V(File_SetPosition, 2) \ |
| + V(File_Truncate, 2) \ |
|
turnidge
2011/11/28 18:39:58
Extra diff? Need to sync?
siva
2011/11/29 00:54:25
Yes, I have synched up now.
On 2011/11/28 18:39:5
|
| V(File_Length, 1) \ |
| V(File_Flush, 1) \ |
| V(File_Create, 1) \ |
| @@ -73,8 +66,8 @@ |
| }; |
| -static Dart_NativeFunction native_lookup(Dart_Handle name, |
| - int argument_count) { |
| +Dart_NativeFunction Builtin::NativeLookup(Dart_Handle name, |
| + int argument_count) { |
| const char* function_name = NULL; |
| Dart_Handle result = Dart_StringToCString(name, &function_name); |
| DART_CHECK_VALID(result); |
| @@ -96,59 +89,39 @@ |
| } |
| -static void SetupCorelibImports(Dart_Handle builtin_lib) { |
| - // Lookup the core libraries and import the builtin library into them. |
| - Dart_Handle url = Dart_NewString(DartUtils::kCoreLibURL); |
| - Dart_Handle core_lib = Dart_LookupLibrary(url); |
| - DART_CHECK_VALID(core_lib); |
| - Dart_Handle result = Dart_LibraryImportLibrary(core_lib, builtin_lib); |
| - DART_CHECK_VALID(result); |
| +// Implementation of native functions which are used for some |
| +// test/debug functionality in standalone dart mode. |
| - url = Dart_NewString(DartUtils::kCoreImplLibURL); |
| - Dart_Handle coreimpl_lib = Dart_LookupLibrary(url); |
| - DART_CHECK_VALID(coreimpl_lib); |
| - result = Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib); |
| - DART_CHECK_VALID(result); |
| +void Builtin::PrintString(FILE* out, Dart_Handle str) { |
| + const char* cstring = NULL; |
| + Dart_Handle result = Dart_StringToCString(str, &cstring); |
| + if (Dart_IsError(result)) { |
| + cstring = Dart_GetError(result); |
| + } |
| + fprintf(out, "%s\n", cstring); |
| + fflush(out); |
| } |
| -Dart_Handle Builtin_Source() { |
| - Dart_Handle str = Dart_NewString(Builtin_source_); |
| - return str; |
| +void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) { |
| + Dart_EnterScope(); |
| + Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0)); |
| + Dart_ExitScope(); |
| } |
| - |
| -void Builtin_SetupLibrary(Dart_Handle builtin_lib) { |
| - // Setup core lib, builtin import structure. |
| - SetupCorelibImports(builtin_lib); |
| - // Setup the native resolver for built in library functions. |
| - Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); |
| - DART_CHECK_VALID(result); |
| +void FUNCTION_NAME(Exit)(Dart_NativeArguments args) { |
| + Dart_EnterScope(); |
| + int64_t status = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| + Dart_ExitScope(); |
| + exit(status); |
| } |
| -void Builtin_ImportLibrary(Dart_Handle library) { |
| +void Builtin::SetNativeResolver() { |
| Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
| Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
| - if (Dart_IsError(builtin_lib)) { |
| - Dart_Handle source = Dart_NewString(Builtin_source_); |
| - builtin_lib = Dart_LoadLibrary(url, source); |
| - if (!Dart_IsError(builtin_lib)) { |
| - Builtin_SetupLibrary(builtin_lib); |
| - } |
| - } |
| - // Import the builtin library into current library. |
| DART_CHECK_VALID(builtin_lib); |
| - Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib); |
| - DART_CHECK_VALID(result); |
| -} |
| - |
| - |
| -void Builtin_SetNativeResolver() { |
| - Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
| - Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
| - DART_CHECK_VALID(builtin_lib); |
| // Setup the native resolver for built in library functions. |
| - Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); |
| + Dart_Handle result = Dart_SetNativeResolver(builtin_lib, NativeLookup); |
| DART_CHECK_VALID(result); |
| } |