OLD | NEW |
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 "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
6 | 6 |
7 #include "bin/crypto.h" | 7 #include "bin/crypto.h" |
8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
9 #include "bin/extensions.h" | 9 #include "bin/extensions.h" |
10 #include "bin/file.h" | 10 #include "bin/file.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 | 50 |
51 struct MagicNumberData { | 51 struct MagicNumberData { |
52 static const intptr_t kLength = 4; | 52 static const intptr_t kLength = 4; |
53 | 53 |
54 const uint8_t bytes[kLength]; | 54 const uint8_t bytes[kLength]; |
55 bool should_skip; | 55 bool should_skip; |
56 }; | 56 }; |
57 | 57 |
58 | 58 |
59 MagicNumberData snapshot_magic_number = { { 0xf5, 0xf5, 0xdc, 0xdc }, true }; | 59 MagicNumberData snapshot_magic_number = {{0xf5, 0xf5, 0xdc, 0xdc}, true}; |
60 MagicNumberData kernel_magic_number = { {0x90, 0xab, 0xcd, 0xef}, false }; | 60 MagicNumberData kernel_magic_number = {{0x90, 0xab, 0xcd, 0xef}, false}; |
61 | 61 |
62 | 62 |
63 bool TryReadKernel(const char* script_uri, | 63 bool TryReadKernel(const char* script_uri, |
64 const uint8_t** kernel_file, | 64 const uint8_t** kernel_file, |
65 intptr_t* kernel_length) { | 65 intptr_t* kernel_length) { |
66 *kernel_file = NULL; | 66 *kernel_file = NULL; |
67 *kernel_length = -1; | 67 *kernel_length = -1; |
68 bool is_kernel_file = false; | 68 bool is_kernel_file = false; |
69 void* script_file = DartUtils::OpenFile(script_uri, false); | 69 void* script_file = DartUtils::OpenFile(script_uri, false); |
70 if (script_file != NULL) { | 70 if (script_file != NULL) { |
71 const uint8_t* buffer = NULL; | 71 const uint8_t* buffer = NULL; |
72 DartUtils::ReadFile(&buffer, kernel_length, script_file); | 72 DartUtils::ReadFile(&buffer, kernel_length, script_file); |
73 DartUtils::CloseFile(script_file); | 73 DartUtils::CloseFile(script_file); |
74 if (*kernel_length > 0 && buffer != NULL) { | 74 if (*kernel_length > 0 && buffer != NULL) { |
75 *kernel_file = buffer; | 75 *kernel_file = buffer; |
76 if (DartUtils::SniffForMagicNumber(&buffer, kernel_length) != | 76 if (DartUtils::SniffForMagicNumber(&buffer, kernel_length) != |
77 DartUtils::kKernelMagicNumber) { | 77 DartUtils::kKernelMagicNumber) { |
78 free(const_cast<uint8_t*>(buffer)); | 78 free(const_cast<uint8_t*>(buffer)); |
79 *kernel_file = NULL; | 79 *kernel_file = NULL; |
80 } else { | 80 } else { |
81 // Do not free buffer if this is a kernel file - kernel_file will be | 81 // Do not free buffer if this is a kernel file - kernel_file will be |
82 // backed by the same memory as the buffer and caller will own it. | 82 // backed by the same memory as the buffer and caller will own it. |
83 // Caller is responsible for freeing the buffer when this function | 83 // Caller is responsible for freeing the buffer when this function |
84 // returns true. | 84 // returns true. |
85 is_kernel_file = true; | 85 is_kernel_file = true; |
86 } | 86 } |
87 } | 87 } |
88 } | 88 } |
89 return is_kernel_file; | 89 return is_kernel_file; |
90 } | 90 } |
91 | 91 |
92 | 92 |
93 static bool IsWindowsHost() { | 93 static bool IsWindowsHost() { |
94 #if defined(TARGET_OS_WINDOWS) | 94 #if defined(TARGET_OS_WINDOWS) |
95 return true; | 95 return true; |
96 #else // defined(TARGET_OS_WINDOWS) | 96 #else // defined(TARGET_OS_WINDOWS) |
97 return false; | 97 return false; |
98 #endif // defined(TARGET_OS_WINDOWS) | 98 #endif // defined(TARGET_OS_WINDOWS) |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 const char* DartUtils::MapLibraryUrl(const char* url_string) { | 102 const char* DartUtils::MapLibraryUrl(const char* url_string) { |
103 ASSERT(url_mapping != NULL); | 103 ASSERT(url_mapping != NULL); |
104 // We need to check if the passed in url is found in the url_mapping array, | 104 // We need to check if the passed in url is found in the url_mapping array, |
105 // in that case use the mapped entry. | 105 // in that case use the mapped entry. |
106 intptr_t len = strlen(url_string); | 106 intptr_t len = strlen(url_string); |
(...skipping 11 matching lines...) Expand all Loading... |
118 | 118 |
119 | 119 |
120 int64_t DartUtils::GetIntegerValue(Dart_Handle value_obj) { | 120 int64_t DartUtils::GetIntegerValue(Dart_Handle value_obj) { |
121 int64_t value = 0; | 121 int64_t value = 0; |
122 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value); | 122 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value); |
123 if (Dart_IsError(result)) Dart_PropagateError(result); | 123 if (Dart_IsError(result)) Dart_PropagateError(result); |
124 return value; | 124 return value; |
125 } | 125 } |
126 | 126 |
127 | 127 |
128 int64_t DartUtils::GetInt64ValueCheckRange( | 128 int64_t DartUtils::GetInt64ValueCheckRange(Dart_Handle value_obj, |
129 Dart_Handle value_obj, int64_t lower, int64_t upper) { | 129 int64_t lower, |
| 130 int64_t upper) { |
130 int64_t value = DartUtils::GetIntegerValue(value_obj); | 131 int64_t value = DartUtils::GetIntegerValue(value_obj); |
131 if (value < lower || upper < value) { | 132 if (value < lower || upper < value) { |
132 Dart_PropagateError(Dart_NewApiError("Value outside expected range")); | 133 Dart_PropagateError(Dart_NewApiError("Value outside expected range")); |
133 } | 134 } |
134 return value; | 135 return value; |
135 } | 136 } |
136 | 137 |
137 | 138 |
138 intptr_t DartUtils::GetIntptrValue(Dart_Handle value_obj) { | 139 intptr_t DartUtils::GetIntptrValue(Dart_Handle value_obj) { |
139 int64_t value = 0; | 140 int64_t value = 0; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 177 |
177 | 178 |
178 Dart_Handle DartUtils::SetIntegerField(Dart_Handle handle, | 179 Dart_Handle DartUtils::SetIntegerField(Dart_Handle handle, |
179 const char* name, | 180 const char* name, |
180 int64_t val) { | 181 int64_t val) { |
181 return Dart_SetField(handle, NewString(name), Dart_NewInteger(val)); | 182 return Dart_SetField(handle, NewString(name), Dart_NewInteger(val)); |
182 } | 183 } |
183 | 184 |
184 | 185 |
185 Dart_Handle DartUtils::SetStringField(Dart_Handle handle, | 186 Dart_Handle DartUtils::SetStringField(Dart_Handle handle, |
186 const char* name, | 187 const char* name, |
187 const char* val) { | 188 const char* val) { |
188 return Dart_SetField(handle, NewString(name), NewString(val)); | 189 return Dart_SetField(handle, NewString(name), NewString(val)); |
189 } | 190 } |
190 | 191 |
191 | 192 |
192 bool DartUtils::IsDartSchemeURL(const char* url_name) { | 193 bool DartUtils::IsDartSchemeURL(const char* url_name) { |
193 static const intptr_t kDartSchemeLen = strlen(kDartScheme); | 194 static const intptr_t kDartSchemeLen = strlen(kDartScheme); |
194 // If the URL starts with "dart:" then it is considered as a special | 195 // If the URL starts with "dart:" then it is considered as a special |
195 // library URL which is handled differently from other URLs. | 196 // library URL which is handled differently from other URLs. |
196 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0); | 197 return (strncmp(url_name, kDartScheme, kDartSchemeLen) == 0); |
197 } | 198 } |
198 | 199 |
199 | 200 |
200 bool DartUtils::IsHttpSchemeURL(const char* url_name) { | 201 bool DartUtils::IsHttpSchemeURL(const char* url_name) { |
201 static const intptr_t kHttpSchemeLen = strlen(kHttpScheme); | 202 static const intptr_t kHttpSchemeLen = strlen(kHttpScheme); |
202 return (strncmp(url_name, kHttpScheme, kHttpSchemeLen) == 0); | 203 return (strncmp(url_name, kHttpScheme, kHttpSchemeLen) == 0); |
203 } | 204 } |
204 | 205 |
205 | 206 |
206 bool DartUtils::IsDartExtensionSchemeURL(const char* url_name) { | 207 bool DartUtils::IsDartExtensionSchemeURL(const char* url_name) { |
207 static const intptr_t kDartExtensionSchemeLen = strlen(kDartExtensionScheme); | 208 static const intptr_t kDartExtensionSchemeLen = strlen(kDartExtensionScheme); |
208 // If the URL starts with "dartext:" then it is considered as a special | 209 // If the URL starts with "dartext:" then it is considered as a special |
209 // extension library URL which is handled differently from other URLs. | 210 // extension library URL which is handled differently from other URLs. |
210 return | 211 return (strncmp(url_name, kDartExtensionScheme, kDartExtensionSchemeLen) == |
211 (strncmp(url_name, kDartExtensionScheme, kDartExtensionSchemeLen) == 0); | 212 0); |
212 } | 213 } |
213 | 214 |
214 | 215 |
215 bool DartUtils::IsDartIOLibURL(const char* url_name) { | 216 bool DartUtils::IsDartIOLibURL(const char* url_name) { |
216 return (strcmp(url_name, kIOLibURL) == 0); | 217 return (strcmp(url_name, kIOLibURL) == 0); |
217 } | 218 } |
218 | 219 |
219 | 220 |
220 bool DartUtils::IsDartBuiltinLibURL(const char* url_name) { | 221 bool DartUtils::IsDartBuiltinLibURL(const char* url_name) { |
221 return (strcmp(url_name, kBuiltinLibURL) == 0); | 222 return (strcmp(url_name, kBuiltinLibURL) == 0); |
222 } | 223 } |
223 | 224 |
224 | 225 |
225 const char* DartUtils::RemoveScheme(const char* url) { | 226 const char* DartUtils::RemoveScheme(const char* url) { |
226 const char* colon = strchr(url, ':'); | 227 const char* colon = strchr(url, ':'); |
227 if (colon == NULL) { | 228 if (colon == NULL) { |
228 return url; | 229 return url; |
229 } else { | 230 } else { |
230 return colon + 1; | 231 return colon + 1; |
231 } | 232 } |
232 } | 233 } |
233 | 234 |
234 | 235 |
235 void* DartUtils::OpenFile(const char* name, bool write) { | 236 void* DartUtils::OpenFile(const char* name, bool write) { |
236 File* file = File::Open(name, write ? File::kWriteTruncate : File::kRead); | 237 File* file = File::Open(name, write ? File::kWriteTruncate : File::kRead); |
237 return reinterpret_cast<void*>(file); | 238 return reinterpret_cast<void*>(file); |
238 } | 239 } |
239 | 240 |
240 | 241 |
241 void DartUtils::ReadFile(const uint8_t** data, | 242 void DartUtils::ReadFile(const uint8_t** data, intptr_t* len, void* stream) { |
242 intptr_t* len, | |
243 void* stream) { | |
244 ASSERT(data != NULL); | 243 ASSERT(data != NULL); |
245 ASSERT(len != NULL); | 244 ASSERT(len != NULL); |
246 ASSERT(stream != NULL); | 245 ASSERT(stream != NULL); |
247 File* file_stream = reinterpret_cast<File*>(stream); | 246 File* file_stream = reinterpret_cast<File*>(stream); |
248 int64_t file_len = file_stream->Length(); | 247 int64_t file_len = file_stream->Length(); |
249 if ((file_len < 0) || (file_len > kIntptrMax)) { | 248 if ((file_len < 0) || (file_len > kIntptrMax)) { |
250 *data = NULL; | 249 *data = NULL; |
251 *len = -1; // Indicates read was not successful. | 250 *len = -1; // Indicates read was not successful. |
252 return; | 251 return; |
253 } | 252 } |
(...skipping 23 matching lines...) Expand all Loading... |
277 File* file = reinterpret_cast<File*>(stream); | 276 File* file = reinterpret_cast<File*>(stream); |
278 file->Release(); | 277 file->Release(); |
279 } | 278 } |
280 | 279 |
281 | 280 |
282 bool DartUtils::EntropySource(uint8_t* buffer, intptr_t length) { | 281 bool DartUtils::EntropySource(uint8_t* buffer, intptr_t length) { |
283 return Crypto::GetRandomBytes(length, buffer); | 282 return Crypto::GetRandomBytes(length, buffer); |
284 } | 283 } |
285 | 284 |
286 | 285 |
287 static Dart_Handle SingleArgDart_Invoke(Dart_Handle lib, const char* method, | 286 static Dart_Handle SingleArgDart_Invoke(Dart_Handle lib, |
| 287 const char* method, |
288 Dart_Handle arg) { | 288 Dart_Handle arg) { |
289 const int kNumArgs = 1; | 289 const int kNumArgs = 1; |
290 Dart_Handle dart_args[kNumArgs]; | 290 Dart_Handle dart_args[kNumArgs]; |
291 dart_args[0] = arg; | 291 dart_args[0] = arg; |
292 return Dart_Invoke(lib, DartUtils::NewString(method), kNumArgs, dart_args); | 292 return Dart_Invoke(lib, DartUtils::NewString(method), kNumArgs, dart_args); |
293 } | 293 } |
294 | 294 |
295 | 295 |
296 // TODO(iposva): Allocate from the zone instead of leaking error string | 296 // TODO(iposva): Allocate from the zone instead of leaking error string |
297 // here. On the other hand the binary is about to exit anyway. | 297 // here. On the other hand the binary is about to exit anyway. |
(...skipping 25 matching lines...) Expand all Loading... |
323 | 323 |
324 | 324 |
325 Dart_Handle DartUtils::ReadStringFromFile(const char* filename) { | 325 Dart_Handle DartUtils::ReadStringFromFile(const char* filename) { |
326 const char* error_msg = NULL; | 326 const char* error_msg = NULL; |
327 intptr_t len; | 327 intptr_t len; |
328 const uint8_t* text_buffer = ReadFileFully(filename, &len, &error_msg); | 328 const uint8_t* text_buffer = ReadFileFully(filename, &len, &error_msg); |
329 if (text_buffer == NULL) { | 329 if (text_buffer == NULL) { |
330 return Dart_NewApiError(error_msg); | 330 return Dart_NewApiError(error_msg); |
331 } | 331 } |
332 Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len); | 332 Dart_Handle str = Dart_NewStringFromUTF8(text_buffer, len); |
333 free(const_cast<uint8_t *>(text_buffer)); | 333 free(const_cast<uint8_t*>(text_buffer)); |
334 return str; | 334 return str; |
335 } | 335 } |
336 | 336 |
337 | 337 |
338 Dart_Handle DartUtils::MakeUint8Array(const uint8_t* buffer, intptr_t len) { | 338 Dart_Handle DartUtils::MakeUint8Array(const uint8_t* buffer, intptr_t len) { |
339 Dart_Handle array = Dart_NewTypedData(Dart_TypedData_kUint8, len); | 339 Dart_Handle array = Dart_NewTypedData(Dart_TypedData_kUint8, len); |
340 RETURN_IF_ERROR(array); | 340 RETURN_IF_ERROR(array); |
341 { | 341 { |
342 Dart_TypedData_Type td_type; | 342 Dart_TypedData_Type td_type; |
343 void* td_data; | 343 void* td_data; |
(...skipping 19 matching lines...) Expand all Loading... |
363 Dart_Handle directory = NewString(original_working_directory); | 363 Dart_Handle directory = NewString(original_working_directory); |
364 return SingleArgDart_Invoke(builtin_lib, "_setWorkingDirectory", directory); | 364 return SingleArgDart_Invoke(builtin_lib, "_setWorkingDirectory", directory); |
365 } | 365 } |
366 | 366 |
367 | 367 |
368 Dart_Handle DartUtils::ResolveUriInWorkingDirectory(Dart_Handle script_uri) { | 368 Dart_Handle DartUtils::ResolveUriInWorkingDirectory(Dart_Handle script_uri) { |
369 const int kNumArgs = 1; | 369 const int kNumArgs = 1; |
370 Dart_Handle dart_args[kNumArgs]; | 370 Dart_Handle dart_args[kNumArgs]; |
371 dart_args[0] = script_uri; | 371 dart_args[0] = script_uri; |
372 return Dart_Invoke(DartUtils::BuiltinLib(), | 372 return Dart_Invoke(DartUtils::BuiltinLib(), |
373 NewString("_resolveInWorkingDirectory"), | 373 NewString("_resolveInWorkingDirectory"), kNumArgs, |
374 kNumArgs, | |
375 dart_args); | 374 dart_args); |
376 } | 375 } |
377 | 376 |
378 | 377 |
379 Dart_Handle DartUtils::LibraryFilePath(Dart_Handle library_uri) { | 378 Dart_Handle DartUtils::LibraryFilePath(Dart_Handle library_uri) { |
380 const int kNumArgs = 1; | 379 const int kNumArgs = 1; |
381 Dart_Handle dart_args[kNumArgs]; | 380 Dart_Handle dart_args[kNumArgs]; |
382 dart_args[0] = library_uri; | 381 dart_args[0] = library_uri; |
383 return Dart_Invoke(DartUtils::BuiltinLib(), | 382 return Dart_Invoke(DartUtils::BuiltinLib(), NewString("_libraryFilePath"), |
384 NewString("_libraryFilePath"), | 383 kNumArgs, dart_args); |
385 kNumArgs, | |
386 dart_args); | |
387 } | 384 } |
388 | 385 |
389 | 386 |
390 Dart_Handle DartUtils::ResolveScript(Dart_Handle url) { | 387 Dart_Handle DartUtils::ResolveScript(Dart_Handle url) { |
391 const int kNumArgs = 1; | 388 const int kNumArgs = 1; |
392 Dart_Handle dart_args[kNumArgs]; | 389 Dart_Handle dart_args[kNumArgs]; |
393 dart_args[0] = url; | 390 dart_args[0] = url; |
394 return Dart_Invoke(DartUtils::BuiltinLib(), | 391 return Dart_Invoke(DartUtils::BuiltinLib(), NewString("_resolveScriptUri"), |
395 NewString("_resolveScriptUri"), | 392 kNumArgs, dart_args); |
396 kNumArgs, | |
397 dart_args); | |
398 } | 393 } |
399 | 394 |
400 | 395 |
401 static Dart_Handle LoadDataAsync_Invoke(Dart_Handle tag, | 396 static Dart_Handle LoadDataAsync_Invoke(Dart_Handle tag, |
402 Dart_Handle url, | 397 Dart_Handle url, |
403 Dart_Handle library_url) { | 398 Dart_Handle library_url) { |
404 const int kNumArgs = 3; | 399 const int kNumArgs = 3; |
405 Dart_Handle dart_args[kNumArgs]; | 400 Dart_Handle dart_args[kNumArgs]; |
406 dart_args[0] = tag; | 401 dart_args[0] = tag; |
407 dart_args[1] = url; | 402 dart_args[1] = url; |
408 dart_args[2] = library_url; | 403 dart_args[2] = library_url; |
409 return Dart_Invoke(DartUtils::BuiltinLib(), | 404 return Dart_Invoke(DartUtils::BuiltinLib(), |
410 DartUtils::NewString("_loadDataAsync"), | 405 DartUtils::NewString("_loadDataAsync"), kNumArgs, |
411 kNumArgs, | |
412 dart_args); | 406 dart_args); |
413 } | 407 } |
414 | 408 |
415 | 409 |
416 Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag, | 410 Dart_Handle DartUtils::LibraryTagHandler(Dart_LibraryTag tag, |
417 Dart_Handle library, | 411 Dart_Handle library, |
418 Dart_Handle url) { | 412 Dart_Handle url) { |
419 Dart_Handle library_url = Dart_LibraryUrl(library); | 413 Dart_Handle library_url = Dart_LibraryUrl(library); |
420 if (Dart_IsError(library_url)) { | 414 if (Dart_IsError(library_url)) { |
421 return library_url; | 415 return library_url; |
(...skipping 16 matching lines...) Expand all Loading... |
438 } | 432 } |
439 | 433 |
440 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); | 434 bool is_dart_scheme_url = DartUtils::IsDartSchemeURL(url_string); |
441 bool is_dart_library = DartUtils::IsDartSchemeURL(library_url_string); | 435 bool is_dart_library = DartUtils::IsDartSchemeURL(library_url_string); |
442 | 436 |
443 // Handle canonicalization, 'import' and 'part' of 'dart:' libraries. | 437 // Handle canonicalization, 'import' and 'part' of 'dart:' libraries. |
444 if (is_dart_scheme_url || is_dart_library) { | 438 if (is_dart_scheme_url || is_dart_library) { |
445 if (tag == Dart_kImportTag) { | 439 if (tag == Dart_kImportTag) { |
446 Builtin::BuiltinLibraryId id = Builtin::FindId(url_string); | 440 Builtin::BuiltinLibraryId id = Builtin::FindId(url_string); |
447 if (id == Builtin::kInvalidLibrary) { | 441 if (id == Builtin::kInvalidLibrary) { |
448 return NewError("The built-in library '%s' is not available" | 442 return NewError( |
449 " on the stand-alone VM.\n", url_string); | 443 "The built-in library '%s' is not available" |
| 444 " on the stand-alone VM.\n", |
| 445 url_string); |
450 } | 446 } |
451 return Builtin::LoadLibrary(url, id); | 447 return Builtin::LoadLibrary(url, id); |
452 } else { | 448 } else { |
453 ASSERT(tag == Dart_kSourceTag); | 449 ASSERT(tag == Dart_kSourceTag); |
454 Builtin::BuiltinLibraryId id = Builtin::FindId(library_url_string); | 450 Builtin::BuiltinLibraryId id = Builtin::FindId(library_url_string); |
455 if (id == Builtin::kInvalidLibrary) { | 451 if (id == Builtin::kInvalidLibrary) { |
456 return NewError("The built-in library '%s' is not available" | 452 return NewError( |
457 " on the stand-alone VM. Trying to load" | 453 "The built-in library '%s' is not available" |
458 " '%s'.\n", library_url_string, url_string); | 454 " on the stand-alone VM. Trying to load" |
| 455 " '%s'.\n", |
| 456 library_url_string, url_string); |
459 } | 457 } |
460 // Prepend the library URI to form a unique script URI for the part. | 458 // Prepend the library URI to form a unique script URI for the part. |
461 intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string); | 459 intptr_t len = snprintf(NULL, 0, "%s/%s", library_url_string, url_string); |
462 char* part_uri = reinterpret_cast<char*>(malloc(len + 1)); | 460 char* part_uri = reinterpret_cast<char*>(malloc(len + 1)); |
463 snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string); | 461 snprintf(part_uri, len + 1, "%s/%s", library_url_string, url_string); |
464 Dart_Handle part_uri_obj = DartUtils::NewString(part_uri); | 462 Dart_Handle part_uri_obj = DartUtils::NewString(part_uri); |
465 free(part_uri); | 463 free(part_uri); |
466 return Dart_LoadSource(library, | 464 return Dart_LoadSource(library, part_uri_obj, Dart_Null(), |
467 part_uri_obj, Dart_Null(), | |
468 Builtin::PartSource(id, url_string), 0, 0); | 465 Builtin::PartSource(id, url_string), 0, 0); |
469 } | 466 } |
470 // All cases should have been handled above. | 467 // All cases should have been handled above. |
471 UNREACHABLE(); | 468 UNREACHABLE(); |
472 } | 469 } |
473 | 470 |
474 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { | 471 if (DartUtils::IsDartExtensionSchemeURL(url_string)) { |
475 // Load a native code shared library to use in a native extension | 472 // Load a native code shared library to use in a native extension |
476 if (tag != Dart_kImportTag) { | 473 if (tag != Dart_kImportTag) { |
477 return NewError("Dart extensions must use import: '%s'", url_string); | 474 return NewError("Dart extensions must use import: '%s'", url_string); |
478 } | 475 } |
479 Dart_Handle library_file_path = DartUtils::LibraryFilePath(library_url); | 476 Dart_Handle library_file_path = DartUtils::LibraryFilePath(library_url); |
480 const char* lib_path_str = NULL; | 477 const char* lib_path_str = NULL; |
481 Dart_StringToCString(library_file_path, &lib_path_str); | 478 Dart_StringToCString(library_file_path, &lib_path_str); |
482 const char* extension_path = DartUtils::RemoveScheme(url_string); | 479 const char* extension_path = DartUtils::RemoveScheme(url_string); |
483 if (strchr(extension_path, '/') != NULL || | 480 if (strchr(extension_path, '/') != NULL || |
484 (IsWindowsHost() && strchr(extension_path, '\\') != NULL)) { | 481 (IsWindowsHost() && strchr(extension_path, '\\') != NULL)) { |
485 return NewError( | 482 return NewError( |
486 "Relative paths for dart extensions are not supported: '%s'", | 483 "Relative paths for dart extensions are not supported: '%s'", |
487 extension_path); | 484 extension_path); |
488 } | 485 } |
489 return Extensions::LoadExtension(lib_path_str, | 486 return Extensions::LoadExtension(lib_path_str, extension_path, library); |
490 extension_path, | |
491 library); | |
492 } | 487 } |
493 | 488 |
494 // Handle 'import' or 'part' requests for all other URIs. Call dart code to | 489 // Handle 'import' or 'part' requests for all other URIs. Call dart code to |
495 // read the source code asynchronously. | 490 // read the source code asynchronously. |
496 return LoadDataAsync_Invoke(Dart_NewInteger(tag), url, library_url); | 491 return LoadDataAsync_Invoke(Dart_NewInteger(tag), url, library_url); |
497 } | 492 } |
498 | 493 |
499 | 494 |
500 static bool CheckMagicNumber(const uint8_t** buf, | 495 static bool CheckMagicNumber(const uint8_t** buf, |
501 intptr_t* len, | 496 intptr_t* len, |
502 const MagicNumberData& magic_number) { | 497 const MagicNumberData& magic_number) { |
503 if ((*len >= MagicNumberData::kLength) && | 498 if ((*len >= MagicNumberData::kLength) && |
504 (memcmp(*buf, magic_number.bytes, MagicNumberData::kLength) == 0)) { | 499 (memcmp(*buf, magic_number.bytes, MagicNumberData::kLength) == 0)) { |
505 if (magic_number.should_skip) { | 500 if (magic_number.should_skip) { |
506 *buf += MagicNumberData::kLength; | 501 *buf += MagicNumberData::kLength; |
507 *len -= MagicNumberData::kLength; | 502 *len -= MagicNumberData::kLength; |
508 } | 503 } |
509 return true; | 504 return true; |
510 } | 505 } |
511 return false; | 506 return false; |
512 } | 507 } |
513 | 508 |
514 | 509 |
515 DartUtils::MagicNumber DartUtils::SniffForMagicNumber(const uint8_t** buf, | 510 DartUtils::MagicNumber DartUtils::SniffForMagicNumber(const uint8_t** buf, |
516 intptr_t* len) { | 511 intptr_t* len) { |
517 if (CheckMagicNumber(buf, len, snapshot_magic_number)) { | 512 if (CheckMagicNumber(buf, len, snapshot_magic_number)) { |
518 return kSnapshotMagicNumber; | 513 return kSnapshotMagicNumber; |
519 } | 514 } |
520 | 515 |
521 if (CheckMagicNumber(buf, len, kernel_magic_number)) { | 516 if (CheckMagicNumber(buf, len, kernel_magic_number)) { |
522 return kKernelMagicNumber; | 517 return kKernelMagicNumber; |
523 } | 518 } |
524 | 519 |
525 return kUnknownMagicNumber; | 520 return kUnknownMagicNumber; |
526 } | 521 } |
527 | 522 |
528 | 523 |
529 void DartUtils::WriteMagicNumber(File* file) { | 524 void DartUtils::WriteMagicNumber(File* file) { |
530 // Write a magic number and version information into the snapshot file. | 525 // Write a magic number and version information into the snapshot file. |
531 bool bytes_written = file->WriteFully(snapshot_magic_number.bytes, | 526 bool bytes_written = |
532 MagicNumberData::kLength); | 527 file->WriteFully(snapshot_magic_number.bytes, MagicNumberData::kLength); |
533 ASSERT(bytes_written); | 528 ASSERT(bytes_written); |
534 } | 529 } |
535 | 530 |
536 | 531 |
537 Dart_Handle DartUtils::LoadScript(const char* script_uri) { | 532 Dart_Handle DartUtils::LoadScript(const char* script_uri) { |
538 Dart_TimelineEvent("LoadScript", | 533 Dart_TimelineEvent("LoadScript", Dart_TimelineGetMicros(), |
539 Dart_TimelineGetMicros(), | 534 Dart_GetMainPortId(), Dart_Timeline_Event_Async_Begin, 0, |
540 Dart_GetMainPortId(), | 535 NULL, NULL); |
541 Dart_Timeline_Event_Async_Begin, | |
542 0, NULL, NULL); | |
543 Dart_Handle uri = Dart_NewStringFromCString(script_uri); | 536 Dart_Handle uri = Dart_NewStringFromCString(script_uri); |
544 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null()); | 537 return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null()); |
545 } | 538 } |
546 | 539 |
547 | 540 |
548 void FUNCTION_NAME(Builtin_GetCurrentDirectory)(Dart_NativeArguments args) { | 541 void FUNCTION_NAME(Builtin_GetCurrentDirectory)(Dart_NativeArguments args) { |
549 const char* current = Directory::Current(); | 542 const char* current = Directory::Current(); |
550 if (current != NULL) { | 543 if (current != NULL) { |
551 Dart_SetReturnValue(args, DartUtils::NewString(current)); | 544 Dart_SetReturnValue(args, DartUtils::NewString(current)); |
552 } else { | 545 } else { |
553 Dart_Handle err = DartUtils::NewError("Failed to get current directory."); | 546 Dart_Handle err = DartUtils::NewError("Failed to get current directory."); |
554 Dart_PropagateError(err); | 547 Dart_PropagateError(err); |
555 } | 548 } |
556 } | 549 } |
557 | 550 |
558 | 551 |
559 Dart_Handle DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, | 552 Dart_Handle DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib, |
560 Dart_Handle internal_lib, | 553 Dart_Handle internal_lib, |
561 bool is_service_isolate, | 554 bool is_service_isolate, |
562 bool trace_loading) { | 555 bool trace_loading) { |
563 // Setup the internal library's 'internalPrint' function. | 556 // Setup the internal library's 'internalPrint' function. |
564 Dart_Handle print = Dart_Invoke( | 557 Dart_Handle print = |
565 builtin_lib, NewString("_getPrintClosure"), 0, NULL); | 558 Dart_Invoke(builtin_lib, NewString("_getPrintClosure"), 0, NULL); |
566 RETURN_IF_ERROR(print); | 559 RETURN_IF_ERROR(print); |
567 Dart_Handle result = | 560 Dart_Handle result = |
568 Dart_SetField(internal_lib, NewString("_printClosure"), print); | 561 Dart_SetField(internal_lib, NewString("_printClosure"), print); |
569 RETURN_IF_ERROR(result); | 562 RETURN_IF_ERROR(result); |
570 | 563 |
571 if (!is_service_isolate) { | 564 if (!is_service_isolate) { |
572 if (IsWindowsHost()) { | 565 if (IsWindowsHost()) { |
573 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); | 566 result = Dart_SetField(builtin_lib, NewString("_isWindows"), Dart_True()); |
574 RETURN_IF_ERROR(result); | 567 RETURN_IF_ERROR(result); |
575 } | 568 } |
576 if (trace_loading) { | 569 if (trace_loading) { |
577 result = Dart_SetField(builtin_lib, | 570 result = |
578 NewString("_traceLoading"), Dart_True()); | 571 Dart_SetField(builtin_lib, NewString("_traceLoading"), Dart_True()); |
579 RETURN_IF_ERROR(result); | 572 RETURN_IF_ERROR(result); |
580 } | 573 } |
581 // Set current working directory. | 574 // Set current working directory. |
582 result = SetWorkingDirectory(); | 575 result = SetWorkingDirectory(); |
583 RETURN_IF_ERROR(result); | 576 RETURN_IF_ERROR(result); |
584 } | 577 } |
585 return Dart_True(); | 578 return Dart_True(); |
586 } | 579 } |
587 | 580 |
588 | 581 |
589 Dart_Handle DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, | 582 Dart_Handle DartUtils::PrepareCoreLibrary(Dart_Handle core_lib, |
590 Dart_Handle builtin_lib, | 583 Dart_Handle builtin_lib, |
591 bool is_service_isolate) { | 584 bool is_service_isolate) { |
592 if (!is_service_isolate) { | 585 if (!is_service_isolate) { |
593 // Setup the 'Uri.base' getter in dart:core. | 586 // Setup the 'Uri.base' getter in dart:core. |
594 Dart_Handle uri_base = Dart_Invoke( | 587 Dart_Handle uri_base = |
595 builtin_lib, NewString("_getUriBaseClosure"), 0, NULL); | 588 Dart_Invoke(builtin_lib, NewString("_getUriBaseClosure"), 0, NULL); |
596 RETURN_IF_ERROR(uri_base); | 589 RETURN_IF_ERROR(uri_base); |
597 Dart_Handle result = Dart_SetField(core_lib, | 590 Dart_Handle result = |
598 NewString("_uriBaseClosure"), | 591 Dart_SetField(core_lib, NewString("_uriBaseClosure"), uri_base); |
599 uri_base); | |
600 RETURN_IF_ERROR(result); | 592 RETURN_IF_ERROR(result); |
601 } | 593 } |
602 return Dart_True(); | 594 return Dart_True(); |
603 } | 595 } |
604 | 596 |
605 | 597 |
606 Dart_Handle DartUtils::PrepareAsyncLibrary(Dart_Handle async_lib, | 598 Dart_Handle DartUtils::PrepareAsyncLibrary(Dart_Handle async_lib, |
607 Dart_Handle isolate_lib) { | 599 Dart_Handle isolate_lib) { |
608 Dart_Handle schedule_immediate_closure = | 600 Dart_Handle schedule_immediate_closure = Dart_Invoke( |
609 Dart_Invoke(isolate_lib, NewString("_getIsolateScheduleImmediateClosure"), | 601 isolate_lib, NewString("_getIsolateScheduleImmediateClosure"), 0, NULL); |
610 0, NULL); | |
611 RETURN_IF_ERROR(schedule_immediate_closure); | 602 RETURN_IF_ERROR(schedule_immediate_closure); |
612 Dart_Handle args[1]; | 603 Dart_Handle args[1]; |
613 args[0] = schedule_immediate_closure; | 604 args[0] = schedule_immediate_closure; |
614 return Dart_Invoke( | 605 return Dart_Invoke(async_lib, NewString("_setScheduleImmediateClosure"), 1, |
615 async_lib, NewString("_setScheduleImmediateClosure"), 1, args); | 606 args); |
616 } | 607 } |
617 | 608 |
618 | 609 |
619 Dart_Handle DartUtils::PrepareIOLibrary(Dart_Handle io_lib) { | 610 Dart_Handle DartUtils::PrepareIOLibrary(Dart_Handle io_lib) { |
620 return Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL); | 611 return Dart_Invoke(io_lib, NewString("_setupHooks"), 0, NULL); |
621 } | 612 } |
622 | 613 |
623 | 614 |
624 Dart_Handle DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { | 615 Dart_Handle DartUtils::PrepareIsolateLibrary(Dart_Handle isolate_lib) { |
625 return Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL); | 616 return Dart_Invoke(isolate_lib, NewString("_setupHooks"), 0, NULL); |
(...skipping 14 matching lines...) Expand all Loading... |
640 Dart_Handle DartUtils::SetupPackageRoot(const char* package_root, | 631 Dart_Handle DartUtils::SetupPackageRoot(const char* package_root, |
641 const char* packages_config) { | 632 const char* packages_config) { |
642 // Set up package root if specified. | 633 // Set up package root if specified. |
643 if (package_root != NULL) { | 634 if (package_root != NULL) { |
644 ASSERT(packages_config == NULL); | 635 ASSERT(packages_config == NULL); |
645 Dart_Handle result = NewString(package_root); | 636 Dart_Handle result = NewString(package_root); |
646 RETURN_IF_ERROR(result); | 637 RETURN_IF_ERROR(result); |
647 const int kNumArgs = 1; | 638 const int kNumArgs = 1; |
648 Dart_Handle dart_args[kNumArgs]; | 639 Dart_Handle dart_args[kNumArgs]; |
649 dart_args[0] = result; | 640 dart_args[0] = result; |
650 result = Dart_Invoke(DartUtils::BuiltinLib(), | 641 result = Dart_Invoke(DartUtils::BuiltinLib(), NewString("_setPackageRoot"), |
651 NewString("_setPackageRoot"), | 642 kNumArgs, dart_args); |
652 kNumArgs, | |
653 dart_args); | |
654 RETURN_IF_ERROR(result); | 643 RETURN_IF_ERROR(result); |
655 } else if (packages_config != NULL) { | 644 } else if (packages_config != NULL) { |
656 Dart_Handle result = NewString(packages_config); | 645 Dart_Handle result = NewString(packages_config); |
657 RETURN_IF_ERROR(result); | 646 RETURN_IF_ERROR(result); |
658 const int kNumArgs = 1; | 647 const int kNumArgs = 1; |
659 Dart_Handle dart_args[kNumArgs]; | 648 Dart_Handle dart_args[kNumArgs]; |
660 dart_args[0] = result; | 649 dart_args[0] = result; |
661 result = Dart_Invoke(DartUtils::BuiltinLib(), | 650 result = Dart_Invoke(DartUtils::BuiltinLib(), NewString("_setPackagesMap"), |
662 NewString("_setPackagesMap"), | 651 kNumArgs, dart_args); |
663 kNumArgs, | |
664 dart_args); | |
665 RETURN_IF_ERROR(result); | 652 RETURN_IF_ERROR(result); |
666 } | 653 } |
667 return Dart_True(); | 654 return Dart_True(); |
668 } | 655 } |
669 | 656 |
670 | 657 |
671 Dart_Handle DartUtils::PrepareForScriptLoading(bool is_service_isolate, | 658 Dart_Handle DartUtils::PrepareForScriptLoading(bool is_service_isolate, |
672 bool trace_loading) { | 659 bool trace_loading) { |
673 // First ensure all required libraries are available. | 660 // First ensure all required libraries are available. |
674 Dart_Handle url = NewString(kCoreLibURL); | 661 Dart_Handle url = NewString(kCoreLibURL); |
(...skipping 23 matching lines...) Expand all Loading... |
698 IsolateData* isolate_data = | 685 IsolateData* isolate_data = |
699 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); | 686 reinterpret_cast<IsolateData*>(Dart_CurrentIsolateData()); |
700 ASSERT(isolate_data != NULL); | 687 ASSERT(isolate_data != NULL); |
701 isolate_data->set_builtin_lib(builtin_lib); | 688 isolate_data->set_builtin_lib(builtin_lib); |
702 | 689 |
703 // We need to ensure that all the scripts loaded so far are finalized | 690 // We need to ensure that all the scripts loaded so far are finalized |
704 // as we are about to invoke some Dart code below to setup closures. | 691 // as we are about to invoke some Dart code below to setup closures. |
705 Dart_Handle result = Dart_FinalizeLoading(false); | 692 Dart_Handle result = Dart_FinalizeLoading(false); |
706 RETURN_IF_ERROR(result); | 693 RETURN_IF_ERROR(result); |
707 | 694 |
708 result = PrepareBuiltinLibrary(builtin_lib, | 695 result = PrepareBuiltinLibrary(builtin_lib, internal_lib, is_service_isolate, |
709 internal_lib, | |
710 is_service_isolate, | |
711 trace_loading); | 696 trace_loading); |
712 RETURN_IF_ERROR(result); | 697 RETURN_IF_ERROR(result); |
713 | 698 |
714 RETURN_IF_ERROR(PrepareAsyncLibrary(async_lib, isolate_lib)); | 699 RETURN_IF_ERROR(PrepareAsyncLibrary(async_lib, isolate_lib)); |
715 RETURN_IF_ERROR(PrepareCoreLibrary( | 700 RETURN_IF_ERROR( |
716 core_lib, builtin_lib, is_service_isolate)); | 701 PrepareCoreLibrary(core_lib, builtin_lib, is_service_isolate)); |
717 RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib)); | 702 RETURN_IF_ERROR(PrepareIsolateLibrary(isolate_lib)); |
718 RETURN_IF_ERROR(PrepareIOLibrary(io_lib)); | 703 RETURN_IF_ERROR(PrepareIOLibrary(io_lib)); |
719 return result; | 704 return result; |
720 } | 705 } |
721 | 706 |
722 | 707 |
723 Dart_Handle DartUtils::SetupIOLibrary(const char* script_uri) { | 708 Dart_Handle DartUtils::SetupIOLibrary(const char* script_uri) { |
724 Dart_Handle io_lib_url = NewString(kIOLibURL); | 709 Dart_Handle io_lib_url = NewString(kIOLibURL); |
725 RETURN_IF_ERROR(io_lib_url); | 710 RETURN_IF_ERROR(io_lib_url); |
726 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); | 711 Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 Dart_Handle args[1]; | 799 Dart_Handle args[1]; |
815 args[0] = NewString(message); | 800 args[0] = NewString(message); |
816 return Dart_New(type, Dart_Null(), 1, args); | 801 return Dart_New(type, Dart_Null(), 1, args); |
817 } else { | 802 } else { |
818 return Dart_New(type, Dart_Null(), 0, NULL); | 803 return Dart_New(type, Dart_Null(), 0, NULL); |
819 } | 804 } |
820 } | 805 } |
821 | 806 |
822 | 807 |
823 Dart_Handle DartUtils::NewDartArgumentError(const char* message) { | 808 Dart_Handle DartUtils::NewDartArgumentError(const char* message) { |
824 return NewDartExceptionWithMessage(kCoreLibURL, | 809 return NewDartExceptionWithMessage(kCoreLibURL, "ArgumentError", message); |
825 "ArgumentError", | |
826 message); | |
827 } | 810 } |
828 | 811 |
829 | 812 |
830 Dart_Handle DartUtils::NewDartUnsupportedError(const char* message) { | 813 Dart_Handle DartUtils::NewDartUnsupportedError(const char* message) { |
831 return NewDartExceptionWithMessage(kCoreLibURL, | 814 return NewDartExceptionWithMessage(kCoreLibURL, "UnsupportedError", message); |
832 "UnsupportedError", | |
833 message); | |
834 } | 815 } |
835 | 816 |
836 | 817 |
837 Dart_Handle DartUtils::NewDartIOException(const char* exception_name, | 818 Dart_Handle DartUtils::NewDartIOException(const char* exception_name, |
838 const char* message, | 819 const char* message, |
839 Dart_Handle os_error) { | 820 Dart_Handle os_error) { |
840 // Create a dart:io exception object of the given type. | 821 // Create a dart:io exception object of the given type. |
841 return NewDartExceptionWithOSError(kIOLibURL, | 822 return NewDartExceptionWithOSError(kIOLibURL, exception_name, message, |
842 exception_name, | |
843 message, | |
844 os_error); | 823 os_error); |
845 } | 824 } |
846 | 825 |
847 | 826 |
848 Dart_Handle DartUtils::NewError(const char* format, ...) { | 827 Dart_Handle DartUtils::NewError(const char* format, ...) { |
849 va_list args; | 828 va_list args; |
850 va_start(args, format); | 829 va_start(args, format); |
851 intptr_t len = vsnprintf(NULL, 0, format, args); | 830 intptr_t len = vsnprintf(NULL, 0, format, args); |
852 va_end(args); | 831 va_end(args); |
853 | 832 |
(...skipping 28 matching lines...) Expand all Loading... |
882 char* new_str = reinterpret_cast<char*>(Dart_ScopeAllocate(len + 2)); | 861 char* new_str = reinterpret_cast<char*>(Dart_ScopeAllocate(len + 2)); |
883 snprintf(new_str, (len + 2), "%s%s", str, File::PathSeparator()); | 862 snprintf(new_str, (len + 2), "%s%s", str, File::PathSeparator()); |
884 return Dart_NewStringFromCString(new_str); | 863 return Dart_NewStringFromCString(new_str); |
885 } | 864 } |
886 | 865 |
887 | 866 |
888 // Statically allocated Dart_CObject instances for immutable | 867 // Statically allocated Dart_CObject instances for immutable |
889 // objects. As these will be used by different threads the use of | 868 // objects. As these will be used by different threads the use of |
890 // these depends on the fact that the marking internally in the | 869 // these depends on the fact that the marking internally in the |
891 // Dart_CObject structure is not marking simple value objects. | 870 // Dart_CObject structure is not marking simple value objects. |
892 Dart_CObject CObject::api_null_ = { Dart_CObject_kNull , { 0 } }; | 871 Dart_CObject CObject::api_null_ = {Dart_CObject_kNull, {0}}; |
893 Dart_CObject CObject::api_true_ = { Dart_CObject_kBool , { true } }; | 872 Dart_CObject CObject::api_true_ = {Dart_CObject_kBool, {true}}; |
894 Dart_CObject CObject::api_false_ = { Dart_CObject_kBool, { false } }; | 873 Dart_CObject CObject::api_false_ = {Dart_CObject_kBool, {false}}; |
895 CObject CObject::null_ = CObject(&api_null_); | 874 CObject CObject::null_ = CObject(&api_null_); |
896 CObject CObject::true_ = CObject(&api_true_); | 875 CObject CObject::true_ = CObject(&api_true_); |
897 CObject CObject::false_ = CObject(&api_false_); | 876 CObject CObject::false_ = CObject(&api_false_); |
898 | 877 |
899 | 878 |
900 CObject* CObject::Null() { | 879 CObject* CObject::Null() { |
901 return &null_; | 880 return &null_; |
902 } | 881 } |
903 | 882 |
904 | 883 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 | 920 |
942 Dart_CObject* CObject::NewIntptr(intptr_t value) { | 921 Dart_CObject* CObject::NewIntptr(intptr_t value) { |
943 // Pointer values passed as intptr_t are always send as int64_t. | 922 // Pointer values passed as intptr_t are always send as int64_t. |
944 Dart_CObject* cobject = New(Dart_CObject_kInt64); | 923 Dart_CObject* cobject = New(Dart_CObject_kInt64); |
945 cobject->value.as_int64 = value; | 924 cobject->value.as_int64 = value; |
946 return cobject; | 925 return cobject; |
947 } | 926 } |
948 | 927 |
949 | 928 |
950 static bool IsHexDigit(char c) { | 929 static bool IsHexDigit(char c) { |
951 return (('0' <= c) && (c <= '9')) | 930 return (('0' <= c) && (c <= '9')) || (('A' <= c) && (c <= 'F')) || |
952 || (('A' <= c) && (c <= 'F')) | 931 (('a' <= c) && (c <= 'f')); |
953 || (('a' <= c) && (c <= 'f')); | |
954 } | 932 } |
955 | 933 |
956 | 934 |
957 static int HexDigitToInt(char c) { | 935 static int HexDigitToInt(char c) { |
958 if (('0' <= c) && (c <= '9')) return c - '0'; | 936 if (('0' <= c) && (c <= '9')) return c - '0'; |
959 if (('A' <= c) && (c <= 'F')) return 10 + (c - 'A'); | 937 if (('A' <= c) && (c <= 'F')) return 10 + (c - 'A'); |
960 return 10 + (c - 'a'); | 938 return 10 + (c - 'a'); |
961 } | 939 } |
962 | 940 |
963 | 941 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 Dart_CObject* CObject::NewUint8Array(intptr_t length) { | 1091 Dart_CObject* CObject::NewUint8Array(intptr_t length) { |
1114 Dart_CObject* cobject = New(Dart_CObject_kTypedData, length); | 1092 Dart_CObject* cobject = New(Dart_CObject_kTypedData, length); |
1115 cobject->value.as_typed_data.type = Dart_TypedData_kUint8; | 1093 cobject->value.as_typed_data.type = Dart_TypedData_kUint8; |
1116 cobject->value.as_typed_data.length = length; | 1094 cobject->value.as_typed_data.length = length; |
1117 cobject->value.as_typed_data.values = reinterpret_cast<uint8_t*>(cobject + 1); | 1095 cobject->value.as_typed_data.values = reinterpret_cast<uint8_t*>(cobject + 1); |
1118 return cobject; | 1096 return cobject; |
1119 } | 1097 } |
1120 | 1098 |
1121 | 1099 |
1122 Dart_CObject* CObject::NewUint32Array(intptr_t length) { | 1100 Dart_CObject* CObject::NewUint32Array(intptr_t length) { |
1123 Dart_CObject* cobject = New(Dart_CObject_kTypedData, 4*length); | 1101 Dart_CObject* cobject = New(Dart_CObject_kTypedData, 4 * length); |
1124 cobject->value.as_typed_data.type = Dart_TypedData_kUint32; | 1102 cobject->value.as_typed_data.type = Dart_TypedData_kUint32; |
1125 cobject->value.as_typed_data.length = length; | 1103 cobject->value.as_typed_data.length = length; |
1126 cobject->value.as_typed_data.values = reinterpret_cast<uint8_t*>(cobject + 1); | 1104 cobject->value.as_typed_data.values = reinterpret_cast<uint8_t*>(cobject + 1); |
1127 return cobject; | 1105 return cobject; |
1128 } | 1106 } |
1129 | 1107 |
1130 | 1108 |
1131 Dart_CObject* CObject::NewExternalUint8Array( | 1109 Dart_CObject* CObject::NewExternalUint8Array( |
1132 intptr_t length, uint8_t* data, void* peer, | 1110 intptr_t length, |
| 1111 uint8_t* data, |
| 1112 void* peer, |
1133 Dart_WeakPersistentHandleFinalizer callback) { | 1113 Dart_WeakPersistentHandleFinalizer callback) { |
1134 Dart_CObject* cobject = New(Dart_CObject_kExternalTypedData); | 1114 Dart_CObject* cobject = New(Dart_CObject_kExternalTypedData); |
1135 cobject->value.as_external_typed_data.type = Dart_TypedData_kUint8; | 1115 cobject->value.as_external_typed_data.type = Dart_TypedData_kUint8; |
1136 cobject->value.as_external_typed_data.length = length; | 1116 cobject->value.as_external_typed_data.length = length; |
1137 cobject->value.as_external_typed_data.data = data; | 1117 cobject->value.as_external_typed_data.data = data; |
1138 cobject->value.as_external_typed_data.peer = peer; | 1118 cobject->value.as_external_typed_data.peer = peer; |
1139 cobject->value.as_external_typed_data.callback = callback; | 1119 cobject->value.as_external_typed_data.callback = callback; |
1140 return cobject; | 1120 return cobject; |
1141 } | 1121 } |
1142 | 1122 |
1143 | 1123 |
1144 Dart_CObject* CObject::NewIOBuffer(int64_t length) { | 1124 Dart_CObject* CObject::NewIOBuffer(int64_t length) { |
1145 // Make sure that we do not have an integer overflow here. Actual check | 1125 // Make sure that we do not have an integer overflow here. Actual check |
1146 // against max elements will be done at the time of writing, as the constant | 1126 // against max elements will be done at the time of writing, as the constant |
1147 // is not part of the public API. | 1127 // is not part of the public API. |
1148 if ((length < 0) || (length > kIntptrMax)) { | 1128 if ((length < 0) || (length > kIntptrMax)) { |
1149 return NULL; | 1129 return NULL; |
1150 } | 1130 } |
1151 uint8_t* data = IOBuffer::Allocate(static_cast<intptr_t>(length)); | 1131 uint8_t* data = IOBuffer::Allocate(static_cast<intptr_t>(length)); |
1152 ASSERT(data != NULL); | 1132 ASSERT(data != NULL); |
1153 return NewExternalUint8Array( | 1133 return NewExternalUint8Array(static_cast<intptr_t>(length), data, data, |
1154 static_cast<intptr_t>(length), data, data, IOBuffer::Finalizer); | 1134 IOBuffer::Finalizer); |
1155 } | 1135 } |
1156 | 1136 |
1157 | 1137 |
1158 void CObject::FreeIOBufferData(Dart_CObject* cobject) { | 1138 void CObject::FreeIOBufferData(Dart_CObject* cobject) { |
1159 ASSERT(cobject->type == Dart_CObject_kExternalTypedData); | 1139 ASSERT(cobject->type == Dart_CObject_kExternalTypedData); |
1160 cobject->value.as_external_typed_data.callback( | 1140 cobject->value.as_external_typed_data.callback( |
1161 NULL, | 1141 NULL, NULL, cobject->value.as_external_typed_data.peer); |
1162 NULL, | |
1163 cobject->value.as_external_typed_data.peer); | |
1164 cobject->value.as_external_typed_data.data = NULL; | 1142 cobject->value.as_external_typed_data.data = NULL; |
1165 } | 1143 } |
1166 | 1144 |
1167 | 1145 |
1168 CObject* CObject::IllegalArgumentError() { | 1146 CObject* CObject::IllegalArgumentError() { |
1169 CObjectArray* result = new CObjectArray(CObject::NewArray(1)); | 1147 CObjectArray* result = new CObjectArray(CObject::NewArray(1)); |
1170 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kArgumentError))); | 1148 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kArgumentError))); |
1171 return result; | 1149 return result; |
1172 } | 1150 } |
1173 | 1151 |
(...skipping 15 matching lines...) Expand all Loading... |
1189 new CObjectString(CObject::NewString(os_error->message())); | 1167 new CObjectString(CObject::NewString(os_error->message())); |
1190 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1168 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
1191 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1169 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
1192 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1170 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
1193 result->SetAt(2, error_message); | 1171 result->SetAt(2, error_message); |
1194 return result; | 1172 return result; |
1195 } | 1173 } |
1196 | 1174 |
1197 } // namespace bin | 1175 } // namespace bin |
1198 } // namespace dart | 1176 } // namespace dart |
OLD | NEW |