| Index: vm/dart_api_impl_test.cc
|
| ===================================================================
|
| --- vm/dart_api_impl_test.cc (revision 4054)
|
| +++ vm/dart_api_impl_test.cc (working copy)
|
| @@ -5,6 +5,7 @@
|
| #include "include/dart_api.h"
|
| #include "platform/assert.h"
|
| #include "platform/utils.h"
|
| +#include "vm/class_finalizer.h"
|
| #include "vm/dart_api_impl.h"
|
| #include "vm/dart_api_state.h"
|
| #include "vm/thread.h"
|
| @@ -2184,7 +2185,8 @@
|
|
|
| static Dart_Handle library_handler(Dart_LibraryTag tag,
|
| Dart_Handle library,
|
| - Dart_Handle url) {
|
| + Dart_Handle url,
|
| + Dart_Handle import_url_map) {
|
| if (tag == kCanonicalizeUrl) {
|
| return url;
|
| }
|
| @@ -2201,38 +2203,39 @@
|
| Dart_Handle source = Dart_NewString(kScriptChars);
|
| Dart_Handle error = Dart_Error("incoming error");
|
| Dart_Handle result;
|
| + Dart_Handle import_map = Dart_NewList(0);
|
|
|
| - result = Dart_LoadScript(Dart_Null(), source, library_handler);
|
| + result = Dart_LoadScript(Dart_Null(), source, library_handler, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.",
|
| Dart_GetError(result));
|
|
|
| - result = Dart_LoadScript(Dart_True(), source, library_handler);
|
| + result = Dart_LoadScript(Dart_True(), source, library_handler, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be of type String.",
|
| Dart_GetError(result));
|
|
|
| - result = Dart_LoadScript(error, source, library_handler);
|
| + result = Dart_LoadScript(error, source, library_handler, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ("incoming error", Dart_GetError(result));
|
|
|
| - result = Dart_LoadScript(url, Dart_Null(), library_handler);
|
| + result = Dart_LoadScript(url, Dart_Null(), library_handler, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ("Dart_LoadScript expects argument 'source' to be non-null.",
|
| Dart_GetError(result));
|
|
|
| - result = Dart_LoadScript(url, Dart_True(), library_handler);
|
| + result = Dart_LoadScript(url, Dart_True(), library_handler, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ(
|
| "Dart_LoadScript expects argument 'source' to be of type String.",
|
| Dart_GetError(result));
|
|
|
| - result = Dart_LoadScript(url, error, library_handler);
|
| + result = Dart_LoadScript(url, error, library_handler, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ("incoming error", Dart_GetError(result));
|
|
|
| // Load a script successfully.
|
| - result = Dart_LoadScript(url, source, library_handler);
|
| + result = Dart_LoadScript(url, source, library_handler, import_map);
|
| EXPECT_VALID(result);
|
|
|
| result = Dart_InvokeStatic(result,
|
| @@ -2247,7 +2250,7 @@
|
| EXPECT_EQ(12345, value);
|
|
|
| // Further calls to LoadScript are errors.
|
| - result = Dart_LoadScript(url, source, library_handler);
|
| + result = Dart_LoadScript(url, source, library_handler, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ("Dart_LoadScript: "
|
| "A script has already been loaded from 'dart:test-lib'.",
|
| @@ -2255,12 +2258,126 @@
|
| }
|
|
|
|
|
| +static const char* var_mapping[] = {
|
| + "GOOGLE3", ".",
|
| + "ABC", "lala",
|
| + "var1", "",
|
| + "var2", "winner",
|
| +};
|
| +static int index = 0;
|
| +
|
| +
|
| +static Dart_Handle import_library_handler(Dart_LibraryTag tag,
|
| + Dart_Handle library,
|
| + Dart_Handle url,
|
| + Dart_Handle import_url_map) {
|
| + if (tag == kCanonicalizeUrl) {
|
| + return url;
|
| + }
|
| + EXPECT(Dart_IsString(url));
|
| + const char* cstr = NULL;
|
| + EXPECT_VALID(Dart_StringToCString(url, &cstr));
|
| + switch (index) {
|
| + case 0:
|
| + EXPECT_STREQ("./weird.dart", cstr);
|
| + break;
|
| + case 1:
|
| + EXPECT_STREQ("abclaladef", cstr);
|
| + break;
|
| + case 2:
|
| + EXPECT_STREQ("winner", cstr);
|
| + break;
|
| + case 3:
|
| + EXPECT_STREQ("abclaladef/extra_weird.dart", cstr);
|
| + break;
|
| + case 4:
|
| + EXPECT_STREQ("winnerwinner", cstr);
|
| + break;
|
| + default:
|
| + EXPECT(false);
|
| + return Api::NewError("invalid callback");
|
| + }
|
| + index += 1;
|
| + return Api::Success();
|
| +}
|
| +
|
| +
|
| +TEST_CASE(LoadImportScript) {
|
| + const char* kScriptChars =
|
| + "#import('$GOOGLE3/weird.dart');"
|
| + "#import('abc${ABC}def');"
|
| + "#import('${var1}$var2');"
|
| + "#import('abc${ABC}def/extra_weird.dart');"
|
| + "#import('$var2$var2');"
|
| + "main() {"
|
| + " return 12345;"
|
| + "}";
|
| + Dart_Handle url = Dart_NewString(TestCase::url());
|
| + Dart_Handle source = Dart_NewString(kScriptChars);
|
| + intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0]));
|
| + Dart_Handle import_map = Dart_NewList(length);
|
| + for (intptr_t i = 0; i < length; i++) {
|
| + Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i]));
|
| + }
|
| + Dart_Handle result = Dart_LoadScript(url,
|
| + source,
|
| + import_library_handler,
|
| + import_map);
|
| + EXPECT(!Dart_IsError(result));
|
| +}
|
| +
|
| +
|
| +TEST_CASE(LoadImportScriptError1) {
|
| + const char* kScriptChars =
|
| + "#import('abc${DEF}def/extra_weird.dart');"
|
| + "main() {"
|
| + " return 12345;"
|
| + "}";
|
| + Dart_Handle url = Dart_NewString(TestCase::url());
|
| + Dart_Handle source = Dart_NewString(kScriptChars);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + Dart_Handle result = Dart_LoadScript(url,
|
| + source,
|
| + import_library_handler,
|
| + import_map);
|
| + EXPECT(Dart_IsError(result));
|
| + EXPECT(strstr(Dart_GetError(result),
|
| + "import variable 'DEF' has not been defined"));
|
| +}
|
| +
|
| +
|
| +TEST_CASE(LoadImportScriptError2) {
|
| + const char* kScriptChars =
|
| + "#import('abc${ABC/extra_weird.dart');"
|
| + "main() {"
|
| + " return 12345;"
|
| + "}";
|
| + Dart_Handle url = Dart_NewString(TestCase::url());
|
| + Dart_Handle source = Dart_NewString(kScriptChars);
|
| + intptr_t length = (sizeof(var_mapping) / sizeof(var_mapping[0]));
|
| + Dart_Handle import_map = Dart_NewList(length);
|
| + for (intptr_t i = 0; i < length; i++) {
|
| + Dart_ListSetAt(import_map, i, Dart_NewString(var_mapping[i]));
|
| + }
|
| + Dart_Handle result = Dart_LoadScript(url,
|
| + source,
|
| + import_library_handler,
|
| + import_map);
|
| + EXPECT(Dart_IsError(result));
|
| + EXPECT(strstr(Dart_GetError(result), "'}' expected"));
|
| +}
|
| +
|
| +
|
| TEST_CASE(LoadScript_CompileError) {
|
| const char* kScriptChars =
|
| ")";
|
| Dart_Handle url = Dart_NewString(TestCase::url());
|
| Dart_Handle source = Dart_NewString(kScriptChars);
|
| - Dart_Handle result = Dart_LoadScript(url, source, library_handler);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + Dart_Handle result = Dart_LoadScript(url,
|
| + source,
|
| + library_handler,
|
| + import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT(strstr(Dart_GetError(result), "unexpected token ')'"));
|
| }
|
| @@ -2277,12 +2394,16 @@
|
| // Create a test library and Load up a test script in it.
|
| Dart_Handle url = Dart_NewString(TestCase::url());
|
| Dart_Handle source = Dart_NewString(kScriptChars);
|
| - Dart_Handle result = Dart_LoadScript(url, source, library_handler);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + Dart_Handle result = Dart_LoadScript(url,
|
| + source,
|
| + library_handler,
|
| + import_map);
|
| EXPECT_VALID(result);
|
|
|
| url = Dart_NewString("library1.dart");
|
| source = Dart_NewString(kLibrary1Chars);
|
| - result = Dart_LoadLibrary(url, source);
|
| + result = Dart_LoadLibrary(url, source, import_map);
|
| EXPECT_VALID(result);
|
|
|
| result = Dart_LookupLibrary(url);
|
| @@ -2316,7 +2437,8 @@
|
| "#library('library1_name');";
|
| Dart_Handle url = Dart_NewString("library1_url");
|
| Dart_Handle source = Dart_NewString(kLibrary1Chars);
|
| - Dart_Handle lib = Dart_LoadLibrary(url, source);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + Dart_Handle lib = Dart_LoadLibrary(url, source, import_map);
|
| Dart_Handle error = Dart_Error("incoming error");
|
| EXPECT_VALID(lib);
|
|
|
| @@ -2354,12 +2476,13 @@
|
|
|
| Dart_Handle url = Dart_NewString("library1_url");
|
| Dart_Handle source = Dart_NewString(kLibrary1Chars);
|
| - Dart_Handle lib1 = Dart_LoadLibrary(url, source);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + Dart_Handle lib1 = Dart_LoadLibrary(url, source, import_map);
|
| EXPECT_VALID(lib1);
|
|
|
| url = Dart_NewString("library2_url");
|
| source = Dart_NewString(kLibrary2Chars);
|
| - Dart_Handle lib2 = Dart_LoadLibrary(url, source);
|
| + Dart_Handle lib2 = Dart_LoadLibrary(url, source, import_map);
|
| EXPECT_VALID(lib2);
|
|
|
| result = Dart_LibraryImportLibrary(Dart_Null(), lib2);
|
| @@ -2408,43 +2531,44 @@
|
|
|
| Dart_Handle url = Dart_NewString("library1_url");
|
| Dart_Handle source = Dart_NewString(kLibrary1Chars);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
|
|
| - result = Dart_LoadLibrary(Dart_Null(), source);
|
| + result = Dart_LoadLibrary(Dart_Null(), source, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.",
|
| Dart_GetError(result));
|
|
|
| - result = Dart_LoadLibrary(Dart_True(), source);
|
| + result = Dart_LoadLibrary(Dart_True(), source, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be of type String.",
|
| Dart_GetError(result));
|
|
|
| - result = Dart_LoadLibrary(error, source);
|
| + result = Dart_LoadLibrary(error, source, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ("incoming error", Dart_GetError(result));
|
|
|
| - result = Dart_LoadLibrary(url, Dart_Null());
|
| + result = Dart_LoadLibrary(url, Dart_Null(), import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ("Dart_LoadLibrary expects argument 'source' to be non-null.",
|
| Dart_GetError(result));
|
|
|
| - result = Dart_LoadLibrary(url, Dart_True());
|
| + result = Dart_LoadLibrary(url, Dart_True(), import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ(
|
| "Dart_LoadLibrary expects argument 'source' to be of type String.",
|
| Dart_GetError(result));
|
|
|
| - result = Dart_LoadLibrary(url, error);
|
| + result = Dart_LoadLibrary(url, error, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ("incoming error", Dart_GetError(result));
|
|
|
| // Success.
|
| - result = Dart_LoadLibrary(url, source);
|
| + result = Dart_LoadLibrary(url, source, import_map);
|
| EXPECT_VALID(result);
|
| EXPECT(Dart_IsLibrary(result));
|
|
|
| // Duplicate library load fails.
|
| - result = Dart_LoadLibrary(url, source);
|
| + result = Dart_LoadLibrary(url, source, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT_STREQ(
|
| "Dart_LoadLibrary: library 'library1_url' has already been loaded.",
|
| @@ -2458,7 +2582,8 @@
|
| ")";
|
| Dart_Handle url = Dart_NewString("library1_url");
|
| Dart_Handle source = Dart_NewString(kLibrary1Chars);
|
| - Dart_Handle result = Dart_LoadLibrary(url, source);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + Dart_Handle result = Dart_LoadLibrary(url, source, import_map);
|
| EXPECT(Dart_IsError(result));
|
| EXPECT(strstr(Dart_GetError(result), "unexpected token ')'"));
|
| }
|
| @@ -2477,7 +2602,8 @@
|
| // Load up a library.
|
| Dart_Handle url = Dart_NewString("library1_url");
|
| Dart_Handle source = Dart_NewString(kLibrary1Chars);
|
| - Dart_Handle lib = Dart_LoadLibrary(url, source);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + Dart_Handle lib = Dart_LoadLibrary(url, source, import_map);
|
| EXPECT_VALID(lib);
|
| EXPECT(Dart_IsLibrary(lib));
|
|
|
| @@ -2590,7 +2716,8 @@
|
| // Load a test script.
|
| Dart_Handle url = Dart_NewString(TestCase::url());
|
| Dart_Handle source = Dart_NewString(kScriptChars);
|
| - Dart_Handle lib = Dart_LoadScript(url, source, library_handler);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + Dart_Handle lib = Dart_LoadScript(url, source, library_handler, import_map);
|
| EXPECT_VALID(lib);
|
| EXPECT(Dart_IsLibrary(lib));
|
|
|
| @@ -2685,15 +2812,16 @@
|
| // Create a test library and Load up a test script in it.
|
| Dart_Handle url = Dart_NewString(TestCase::url());
|
| Dart_Handle source = Dart_NewString(kScriptChars);
|
| - result = Dart_LoadScript(url, source, library_handler);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + result = Dart_LoadScript(url, source, library_handler, import_map);
|
|
|
| url = Dart_NewString("library1.dart");
|
| source = Dart_NewString(kLibrary1Chars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| url = Dart_NewString("library2.dart");
|
| source = Dart_NewString(kLibrary2Chars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| result = Dart_InvokeStatic(result,
|
| Dart_NewString(""),
|
| @@ -2724,15 +2852,16 @@
|
| // Create a test library and Load up a test script in it.
|
| Dart_Handle url = Dart_NewString(TestCase::url());
|
| Dart_Handle source = Dart_NewString(kScriptChars);
|
| - result = Dart_LoadScript(url, source, library_handler);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + result = Dart_LoadScript(url, source, library_handler, import_map);
|
|
|
| url = Dart_NewString("library1.dart");
|
| source = Dart_NewString(kLibrary1Chars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| url = Dart_NewString("library2.dart");
|
| source = Dart_NewString(kLibrary2Chars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| result = Dart_InvokeStatic(result,
|
| Dart_NewString(""),
|
| @@ -2760,15 +2889,16 @@
|
| // Create a test library and Load up a test script in it.
|
| Dart_Handle url = Dart_NewString(TestCase::url());
|
| Dart_Handle source = Dart_NewString(kScriptChars);
|
| - result = Dart_LoadScript(url, source, library_handler);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + result = Dart_LoadScript(url, source, library_handler, import_map);
|
|
|
| url = Dart_NewString("library2.dart");
|
| source = Dart_NewString(kLibrary2Chars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| url = Dart_NewString("library1.dart");
|
| source = Dart_NewString(kLibrary1Chars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| result = Dart_InvokeStatic(result,
|
| Dart_NewString(""),
|
| @@ -2818,31 +2948,32 @@
|
| // Create a test library and Load up a test script in it.
|
| Dart_Handle url = Dart_NewString(TestCase::url());
|
| Dart_Handle source = Dart_NewString(kScriptChars);
|
| - result = Dart_LoadScript(url, source, library_handler);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + result = Dart_LoadScript(url, source, library_handler, import_map);
|
|
|
| url = Dart_NewString("libraryA.dart");
|
| source = Dart_NewString(kLibraryAChars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| url = Dart_NewString("libraryC.dart");
|
| source = Dart_NewString(kLibraryCChars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| url = Dart_NewString("libraryB.dart");
|
| source = Dart_NewString(kLibraryBChars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| url = Dart_NewString("libraryD.dart");
|
| source = Dart_NewString(kLibraryDChars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| url = Dart_NewString("libraryF.dart");
|
| source = Dart_NewString(kLibraryFChars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| url = Dart_NewString("libraryE.dart");
|
| source = Dart_NewString(kLibraryEChars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| result = Dart_InvokeStatic(result,
|
| Dart_NewString(""),
|
| @@ -2873,11 +3004,12 @@
|
| // Create a test library and Load up a test script in it.
|
| Dart_Handle url = Dart_NewString(TestCase::url());
|
| Dart_Handle source = Dart_NewString(kScriptChars);
|
| - result = Dart_LoadScript(url, source, library_handler);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + result = Dart_LoadScript(url, source, library_handler, import_map);
|
|
|
| url = Dart_NewString("lib.dart");
|
| source = Dart_NewString(kLibraryChars);
|
| - Dart_LoadLibrary(url, source);
|
| + Dart_LoadLibrary(url, source, import_map);
|
|
|
| result = Dart_InvokeStatic(result,
|
| Dart_NewString(""),
|
| @@ -3008,7 +3140,11 @@
|
| Dart_EnterScope();
|
| Dart_Handle url = Dart_NewString(TestCase::url());
|
| Dart_Handle source = Dart_NewString(kScriptChars);
|
| - Dart_Handle lib = Dart_LoadScript(url, source, TestCase::library_handler);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + Dart_Handle lib = Dart_LoadScript(url,
|
| + source,
|
| + TestCase::library_handler,
|
| + import_map);
|
| EXPECT_VALID(lib);
|
| Dart_ExitScope();
|
| return true;
|
| @@ -3120,7 +3256,8 @@
|
| Dart_EnterScope();
|
| Dart_Handle url = Dart_NewString(TestCase::url());
|
| Dart_Handle source = Dart_NewString(kScriptChars);
|
| - lib = Dart_LoadScript(url, source, TestCase::library_handler);
|
| + Dart_Handle import_map = Dart_NewList(0);
|
| + lib = Dart_LoadScript(url, source, TestCase::library_handler, import_map);
|
| EXPECT_VALID(lib);
|
| Dart_Handle result = Dart_SetNativeResolver(
|
| lib, &IsolateInterruptTestNativeLookup);
|
|
|