| Index: runtime/bin/dartutils.cc
|
| diff --git a/runtime/bin/dartutils.cc b/runtime/bin/dartutils.cc
|
| index c2eb2e0eae756a53e87a9c98b4a38186e3fa1620..d8f6549ca35d057a3fcc6876cda952ddbefe0b1a 100644
|
| --- a/runtime/bin/dartutils.cc
|
| +++ b/runtime/bin/dartutils.cc
|
| @@ -15,6 +15,7 @@
|
| #include "bin/extensions.h"
|
| #include "bin/file.h"
|
| #include "bin/io_buffer.h"
|
| +#include "bin/platform.h"
|
| #include "bin/socket.h"
|
| #include "bin/utils.h"
|
|
|
| @@ -477,6 +478,13 @@ void DartUtils::WriteMagicNumber(File* file) {
|
| Dart_Handle DartUtils::LoadScript(const char* script_uri,
|
| Dart_Handle builtin_lib) {
|
| Dart_Handle uri = Dart_NewStringFromCString(script_uri);
|
| +
|
| + Dart_Port load_port = Dart_ServiceWaitForLoadPort();
|
| + if (load_port == ILLEGAL_PORT) {
|
| + return NewDartUnsupportedError("Service did not return load port.");
|
| + }
|
| + Builtin::SetLoadPort(load_port);
|
| +
|
| return LoadDataAsync_Invoke(Dart_Null(), uri, Dart_Null(), builtin_lib);
|
| }
|
|
|
| @@ -590,96 +598,140 @@ void FUNCTION_NAME(Builtin_DoneLoading)(Dart_NativeArguments args) {
|
| }
|
|
|
|
|
| -Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root,
|
| - Dart_Handle builtin_lib) {
|
| - // First ensure all required libraries are available.
|
| - Dart_Handle url = NewString(kAsyncLibURL);
|
| - DART_CHECK_VALID(url);
|
| - Dart_Handle async_lib = Dart_LookupLibrary(url);
|
| - DART_CHECK_VALID(async_lib);
|
| - Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
|
| +void FUNCTION_NAME(Builtin_NativeLibraryExtension)(Dart_NativeArguments args) {
|
| + const char* suffix = Platform::LibraryExtension();
|
| + ASSERT(suffix != NULL);
|
| + Dart_Handle res = Dart_NewStringFromCString(suffix);
|
| + if (Dart_IsError(res)) {
|
| + Dart_PropagateError(res);
|
| + }
|
| + Dart_SetReturnValue(args, res);
|
| +}
|
|
|
| - // We need to ensure that all the scripts loaded so far are finalized
|
| - // as we are about to invoke some Dart code below to setup closures.
|
| - Dart_Handle result = Dart_FinalizeLoading(false);
|
| - DART_CHECK_VALID(result);
|
| +
|
| +void DartUtils::PrepareBuiltinLibrary(Dart_Handle builtin_lib,
|
| + const char* package_root) {
|
| + Dart_Handle url = NewString(kInternalLibURL);
|
| + DART_CHECK_VALID(url);
|
| + Dart_Handle internal_lib = Dart_LookupLibrary(url);
|
| + DART_CHECK_VALID(internal_lib);
|
|
|
| // Setup the internal library's 'internalPrint' function.
|
| Dart_Handle print = Dart_Invoke(
|
| builtin_lib, NewString("_getPrintClosure"), 0, NULL);
|
| - url = NewString(kInternalLibURL);
|
| + DART_CHECK_VALID(print);
|
| + Dart_Handle result =
|
| + Dart_SetField(internal_lib, NewString("_printClosure"), print);
|
| + DART_CHECK_VALID(result);
|
| +
|
| + if (IsWindowsHost()) {
|
| + // Set running on Windows flag.
|
| + result = Dart_Invoke(builtin_lib, NewString("_setWindows"), 0, NULL);
|
| + DART_CHECK_VALID(result);
|
| + }
|
| +
|
| + // Set current working directory.
|
| + result = SetWorkingDirectory(builtin_lib);
|
| + DART_CHECK_VALID(result);
|
| +
|
| + // Set up package root if specified.
|
| + if (package_root != NULL) {
|
| + result = NewString(package_root);
|
| + DART_CHECK_VALID(result);
|
| + const int kNumArgs = 1;
|
| + Dart_Handle dart_args[kNumArgs];
|
| + dart_args[0] = result;
|
| + result = Dart_Invoke(builtin_lib,
|
| + NewString("_setPackageRoot"),
|
| + kNumArgs,
|
| + dart_args);
|
| + DART_CHECK_VALID(result);
|
| + }
|
| +}
|
| +
|
| +
|
| +void DartUtils::PrepareCoreLibrary(Dart_Handle builtin_lib) {
|
| + Dart_Handle url = NewString(kCoreLibURL);
|
| DART_CHECK_VALID(url);
|
| - Dart_Handle internal_lib = Dart_LookupLibrary(url);
|
| - DART_CHECK_VALID(internal_lib);
|
| - result = Dart_SetField(internal_lib,
|
| - NewString("_printClosure"),
|
| - print);
|
| + Dart_Handle core_lib = Dart_LookupLibrary(url);
|
| + DART_CHECK_VALID(core_lib);
|
| +
|
| + // Setup the 'Uri.base' getter in dart:core.
|
| + Dart_Handle uri_base = Dart_Invoke(
|
| + builtin_lib, NewString("_getUriBaseClosure"), 0, NULL);
|
| + DART_CHECK_VALID(uri_base);
|
| + Dart_Handle result = Dart_SetField(core_lib,
|
| + NewString("_uriBaseClosure"),
|
| + uri_base);
|
| DART_CHECK_VALID(result);
|
| +}
|
|
|
| - // Setup the 'timer' factory.
|
| +
|
| +void DartUtils::PrepareAsyncLibrary(Dart_Handle async_lib,
|
| + Dart_Handle io_lib) {
|
| + Dart_Handle url = NewString(kIsolateLibURL);
|
| + DART_CHECK_VALID(url);
|
| + Dart_Handle isolate_lib = Dart_LookupLibrary(url);
|
| + DART_CHECK_VALID(isolate_lib);
|
| +
|
| + // Setup the 'timer' factory in dart:async.
|
| Dart_Handle timer_closure =
|
| Dart_Invoke(io_lib, NewString("_getTimerFactoryClosure"), 0, NULL);
|
| + DART_CHECK_VALID(timer_closure);
|
| Dart_Handle args[1];
|
| args[0] = timer_closure;
|
| DART_CHECK_VALID(Dart_Invoke(
|
| async_lib, NewString("_setTimerFactoryClosure"), 1, args));
|
|
|
| - // Setup the 'scheduleImmediate' closure.
|
| - url = NewString(kIsolateLibURL);
|
| - DART_CHECK_VALID(url);
|
| - Dart_Handle isolate_lib = Dart_LookupLibrary(url);
|
| - DART_CHECK_VALID(isolate_lib);
|
| + // Setup the 'scheduleImmediate' closure in dart:async.
|
| Dart_Handle schedule_immediate_closure =
|
| Dart_Invoke(isolate_lib, NewString("_getIsolateScheduleImmediateClosure"),
|
| 0, NULL);
|
| args[0] = schedule_immediate_closure;
|
| DART_CHECK_VALID(Dart_Invoke(
|
| async_lib, NewString("_setScheduleImmediateClosure"), 1, args));
|
| +}
|
| +
|
|
|
| - // Setup the corelib 'Uri.base' getter.
|
| - url = NewString(kCoreLibURL);
|
| +Dart_Handle DartUtils::PrepareForScriptLoading(const char* package_root,
|
| + Dart_Handle builtin_lib) {
|
| + // First ensure all required libraries are available.
|
| + Dart_Handle url = NewString(kAsyncLibURL);
|
| DART_CHECK_VALID(url);
|
| - Dart_Handle corelib = Dart_LookupLibrary(url);
|
| - DART_CHECK_VALID(corelib);
|
| - Dart_Handle uri_base = Dart_Invoke(
|
| - builtin_lib, NewString("_getUriBaseClosure"), 0, NULL);
|
| - DART_CHECK_VALID(uri_base);
|
| - result = Dart_SetField(corelib,
|
| - NewString("_uriBaseClosure"),
|
| - uri_base);
|
| - DART_CHECK_VALID(result);
|
| + Dart_Handle async_lib = Dart_LookupLibrary(url);
|
| + DART_CHECK_VALID(async_lib);
|
| + Dart_Handle io_lib = Builtin::LoadAndCheckLibrary(Builtin::kIOLibrary);
|
|
|
| - if (IsWindowsHost()) {
|
| - // Set running on Windows flag.
|
| - result = Dart_Invoke(builtin_lib, NewString("_setWindows"), 0, NULL);
|
| - if (Dart_IsError(result)) {
|
| - return result;
|
| - }
|
| - }
|
| + // We need to ensure that all the scripts loaded so far are finalized
|
| + // as we are about to invoke some Dart code below to setup closures.
|
| + Dart_Handle result = Dart_FinalizeLoading(false);
|
| + DART_CHECK_VALID(result);
|
|
|
| - // Set current working directory.
|
| - result = SetWorkingDirectory(builtin_lib);
|
| - if (Dart_IsError(result)) {
|
| - return result;
|
| - }
|
| + PrepareBuiltinLibrary(builtin_lib, package_root);
|
| + PrepareAsyncLibrary(async_lib, io_lib);
|
| + PrepareCoreLibrary(builtin_lib);
|
|
|
| - // Set up package root if specified.
|
| - if (package_root != NULL) {
|
| - result = NewString(package_root);
|
| - if (!Dart_IsError(result)) {
|
| - const int kNumArgs = 1;
|
| - Dart_Handle dart_args[kNumArgs];
|
| - dart_args[0] = result;
|
| - return Dart_Invoke(builtin_lib,
|
| - NewString("_setPackageRoot"),
|
| - kNumArgs,
|
| - dart_args);
|
| - }
|
| - }
|
| return result;
|
| }
|
|
|
|
|
| +void DartUtils::SetupIOLibrary(const char* script_uri) {
|
| + Dart_Handle io_lib_url = NewString(kIOLibURL);
|
| + DART_CHECK_VALID(io_lib_url);
|
| + Dart_Handle io_lib = Dart_LookupLibrary(io_lib_url);
|
| + DART_CHECK_VALID(io_lib);
|
| + Dart_Handle platform_type = GetDartType(DartUtils::kIOLibURL, "_Platform");
|
| + DART_CHECK_VALID(platform_type);
|
| + Dart_Handle script_name = NewString("_nativeScript");
|
| + DART_CHECK_VALID(script_name);
|
| + Dart_Handle dart_script = NewString(script_uri);
|
| + DART_CHECK_VALID(dart_script);
|
| + Dart_Handle set_script_name =
|
| + Dart_SetField(platform_type, script_name, dart_script);
|
| + DART_CHECK_VALID(set_script_name);
|
| +}
|
| +
|
| +
|
| bool DartUtils::PostNull(Dart_Port port_id) {
|
| // Post a message with just the null object.
|
| return Dart_PostCObject(port_id, CObject::Null()->AsApiCObject());
|
| @@ -769,6 +821,13 @@ Dart_Handle DartUtils::NewDartArgumentError(const char* message) {
|
| }
|
|
|
|
|
| +Dart_Handle DartUtils::NewDartUnsupportedError(const char* message) {
|
| + return NewDartExceptionWithMessage(kCoreLibURL,
|
| + "UnsupportedError",
|
| + message);
|
| +}
|
| +
|
| +
|
| Dart_Handle DartUtils::NewDartIOException(const char* exception_name,
|
| const char* message,
|
| Dart_Handle os_error) {
|
|
|