| OLD | NEW |
| 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 #include "bin/builtin.h" | 10 #include "bin/builtin.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 // List all native functions implemented in standalone dart that is used | 22 // List all native functions implemented in standalone dart that is used |
| 23 // to inject additional functionality e.g: Logger, file I/O, socket I/O etc. | 23 // to inject additional functionality e.g: Logger, file I/O, socket I/O etc. |
| 24 #define BUILTIN_NATIVE_LIST(V) \ | 24 #define BUILTIN_NATIVE_LIST(V) \ |
| 25 V(Logger_PrintString, 1) \ | 25 V(Logger_PrintString, 1) \ |
| 26 V(Directory_List, 7) \ | 26 V(Directory_List, 7) \ |
| 27 V(Directory_Exists, 2) \ | 27 V(Directory_Exists, 2) \ |
| 28 V(Directory_Create, 2) \ | 28 V(Directory_Create, 2) \ |
| 29 V(Directory_Delete, 2) \ | 29 V(Directory_Delete, 2) \ |
| 30 V(File_OpenFile, 3) \ | 30 V(File_OpenFile, 3) \ |
| 31 V(File_Exists, 1) \ | 31 V(File_Exists, 2) \ |
| 32 V(File_Close, 1) \ | 32 V(File_Close, 1) \ |
| 33 V(File_ReadByte, 1) \ | 33 V(File_ReadByte, 1) \ |
| 34 V(File_WriteByte, 2) \ | 34 V(File_WriteByte, 2) \ |
| 35 V(File_WriteString, 2) \ | 35 V(File_WriteString, 2) \ |
| 36 V(File_ReadList, 4) \ | 36 V(File_ReadList, 4) \ |
| 37 V(File_WriteList , 4) \ | 37 V(File_WriteList , 4) \ |
| 38 V(File_Position, 1) \ | 38 V(File_Position, 1) \ |
| 39 V(File_Length, 1) \ | 39 V(File_Length, 1) \ |
| 40 V(File_Flush, 1) \ | 40 V(File_Flush, 1) \ |
| 41 V(EventHandler_Start, 1) \ | 41 V(EventHandler_Start, 1) \ |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 ASSERT(Dart_IsValid(result)); | 106 ASSERT(Dart_IsValid(result)); |
| 107 | 107 |
| 108 Dart_Handle coreimpl_lib = | 108 Dart_Handle coreimpl_lib = |
| 109 Dart_LookupLibrary(Dart_NewString("dart:coreimpl")); | 109 Dart_LookupLibrary(Dart_NewString("dart:coreimpl")); |
| 110 ASSERT(Dart_IsValid(coreimpl_lib)); | 110 ASSERT(Dart_IsValid(coreimpl_lib)); |
| 111 result = Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib); | 111 result = Dart_LibraryImportLibrary(coreimpl_lib, builtin_lib); |
| 112 ASSERT(Dart_IsValid(result)); | 112 ASSERT(Dart_IsValid(result)); |
| 113 result = Dart_LibraryImportLibrary(builtin_lib, coreimpl_lib); | 113 result = Dart_LibraryImportLibrary(builtin_lib, coreimpl_lib); |
| 114 ASSERT(Dart_IsValid(result)); | 114 ASSERT(Dart_IsValid(result)); |
| 115 | 115 |
| 116 // Create a native wrapper "FileNativeWrapper" so that we can add a | |
| 117 // native field to store the OS file handle for implementing all the | |
| 118 // file operations. The class "File" extends "FileNativeWrapper". | |
| 119 Dart_Handle name = Dart_NewString("FileNativeWrapper"); | |
| 120 const int kNumFileFields = 1; | |
| 121 result = Dart_CreateNativeWrapperClass(builtin_lib, name, kNumFileFields); | |
| 122 ASSERT(Dart_IsValid(result)); | |
| 123 | |
| 124 // Create a native wrapper "EventHandlerNativeWrapper" so that we can add a | 116 // Create a native wrapper "EventHandlerNativeWrapper" so that we can add a |
| 125 // native field to store the event handle for implementing all | 117 // native field to store the event handle for implementing all |
| 126 // event operations. | 118 // event operations. |
| 127 name = Dart_NewString("EventHandlerNativeWrapper"); | 119 Dart_Handle name = Dart_NewString("EventHandlerNativeWrapper"); |
| 128 const int kNumEventHandlerFields = 1; | 120 const int kNumEventHandlerFields = 1; |
| 129 result = Dart_CreateNativeWrapperClass(builtin_lib, | 121 result = Dart_CreateNativeWrapperClass(builtin_lib, |
| 130 name, | 122 name, |
| 131 kNumEventHandlerFields); | 123 kNumEventHandlerFields); |
| 132 ASSERT(Dart_IsValid(result)); | 124 ASSERT(Dart_IsValid(result)); |
| 133 } | 125 } |
| 134 | 126 |
| 135 | 127 |
| 136 void Builtin_ImportLibrary(Dart_Handle library) { | 128 void Builtin_ImportLibrary(Dart_Handle library) { |
| 137 Builtin_LoadLibrary(); | 129 Builtin_LoadLibrary(); |
| 138 | 130 |
| 139 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 131 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
| 140 Dart_Handle builtin_lib = Dart_LookupLibrary(url); | 132 Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
| 141 ASSERT(Dart_IsValid(builtin_lib)); | 133 ASSERT(Dart_IsValid(builtin_lib)); |
| 142 Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib); | 134 Dart_Handle result = Dart_LibraryImportLibrary(library, builtin_lib); |
| 143 ASSERT(Dart_IsValid(result)); | 135 ASSERT(Dart_IsValid(result)); |
| 144 } | 136 } |
| 145 | 137 |
| 146 | 138 |
| 147 void Builtin_SetNativeResolver() { | 139 void Builtin_SetNativeResolver() { |
| 148 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); | 140 Dart_Handle url = Dart_NewString(DartUtils::kBuiltinLibURL); |
| 149 Dart_Handle builtin_lib = Dart_LookupLibrary(url); | 141 Dart_Handle builtin_lib = Dart_LookupLibrary(url); |
| 150 ASSERT(Dart_IsValid(builtin_lib)); | 142 ASSERT(Dart_IsValid(builtin_lib)); |
| 151 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); | 143 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, native_lookup); |
| 152 ASSERT(Dart_IsValid(result)); | 144 ASSERT(Dart_IsValid(result)); |
| 153 } | 145 } |
| OLD | NEW |