| 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 // TODO(zra): Remove when tests are ready to enable. | 5 // TODO(zra): Remove when tests are ready to enable. |
| 6 #include "platform/globals.h" | 6 #include "platform/globals.h" |
| 7 #if !defined(TARGET_ARCH_ARM64) | 7 #if !defined(TARGET_ARCH_ARM64) |
| 8 | 8 |
| 9 #include "bin/builtin.h" | 9 #include "bin/builtin.h" |
| 10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| (...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 " a.setInt8(i, 0x42);" | 1382 " a.setInt8(i, 0x42);" |
| 1383 " }" | 1383 " }" |
| 1384 " for (int i = 0; i < length; i+=2) {" | 1384 " for (int i = 0; i < length; i+=2) {" |
| 1385 " Expect.equals(0x4242, a.getInt16(i));" | 1385 " Expect.equals(0x4242, a.getInt16(i));" |
| 1386 " }" | 1386 " }" |
| 1387 " return a;" | 1387 " return a;" |
| 1388 "}\n"; | 1388 "}\n"; |
| 1389 // Create a test library and Load up a test script in it. | 1389 // Create a test library and Load up a test script in it. |
| 1390 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1390 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 1391 | 1391 |
| 1392 Dart_Handle result = Dart_SetNativeResolver(lib, &ByteDataNativeResolver); | 1392 Dart_Handle result = |
| 1393 Dart_SetNativeResolver(lib, &ByteDataNativeResolver, NULL); |
| 1393 EXPECT_VALID(result); | 1394 EXPECT_VALID(result); |
| 1394 | 1395 |
| 1395 // Invoke 'main' function. | 1396 // Invoke 'main' function. |
| 1396 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1397 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 1397 EXPECT_VALID(result); | 1398 EXPECT_VALID(result); |
| 1398 } | 1399 } |
| 1399 | 1400 |
| 1400 | 1401 |
| 1401 static const intptr_t kExtLength = 16; | 1402 static const intptr_t kExtLength = 16; |
| 1402 static int8_t data[kExtLength] = { 0x41, 0x42, 0x41, 0x42, | 1403 static int8_t data[kExtLength] = { 0x41, 0x42, 0x41, 0x42, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1450 " }" | 1451 " }" |
| 1451 " for (int i = 0; i < length; i+=2) {" | 1452 " for (int i = 0; i < length; i+=2) {" |
| 1452 " Expect.equals(0x2824, a.getInt16(i, Endianness.LITTLE_ENDIAN));" | 1453 " Expect.equals(0x2824, a.getInt16(i, Endianness.LITTLE_ENDIAN));" |
| 1453 " }" | 1454 " }" |
| 1454 " return a;" | 1455 " return a;" |
| 1455 "}\n"; | 1456 "}\n"; |
| 1456 // Create a test library and Load up a test script in it. | 1457 // Create a test library and Load up a test script in it. |
| 1457 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1458 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 1458 | 1459 |
| 1459 Dart_Handle result = Dart_SetNativeResolver(lib, | 1460 Dart_Handle result = Dart_SetNativeResolver(lib, |
| 1460 &ExternalByteDataNativeResolver); | 1461 &ExternalByteDataNativeResolver, |
| 1462 NULL); |
| 1461 EXPECT_VALID(result); | 1463 EXPECT_VALID(result); |
| 1462 | 1464 |
| 1463 // Invoke 'main' function. | 1465 // Invoke 'main' function. |
| 1464 result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1466 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 1465 EXPECT_VALID(result); | 1467 EXPECT_VALID(result); |
| 1466 | 1468 |
| 1467 for (intptr_t i = 0; i < kExtLength; i+=2) { | 1469 for (intptr_t i = 0; i < kExtLength; i+=2) { |
| 1468 EXPECT_EQ(0x24, data[i]); | 1470 EXPECT_EQ(0x24, data[i]); |
| 1469 EXPECT_EQ(0x28, data[i+1]); | 1471 EXPECT_EQ(0x28, data[i+1]); |
| 1470 } | 1472 } |
| (...skipping 4639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6110 const String& patch_source = String::Handle(String::New(patches[i])); | 6112 const String& patch_source = String::Handle(String::New(patches[i])); |
| 6111 const Script& patch_script = Script::Handle(Script::New( | 6113 const Script& patch_script = Script::Handle(Script::New( |
| 6112 patch_url, patch_source, RawScript::kPatchTag)); | 6114 patch_url, patch_source, RawScript::kPatchTag)); |
| 6113 | 6115 |
| 6114 const Error& err = Error::Handle(lib.Patch(patch_script)); | 6116 const Error& err = Error::Handle(lib.Patch(patch_script)); |
| 6115 if (!err.IsNull()) { | 6117 if (!err.IsNull()) { |
| 6116 OS::Print("Patching error: %s\n", err.ToErrorCString()); | 6118 OS::Print("Patching error: %s\n", err.ToErrorCString()); |
| 6117 EXPECT(false); | 6119 EXPECT(false); |
| 6118 } | 6120 } |
| 6119 } | 6121 } |
| 6120 result = Dart_SetNativeResolver(result, &PatchNativeResolver); | 6122 result = Dart_SetNativeResolver(result, &PatchNativeResolver, NULL); |
| 6121 EXPECT_VALID(result); | 6123 EXPECT_VALID(result); |
| 6122 | 6124 |
| 6123 Dart_Handle script_url = NewString("theScript"); | 6125 Dart_Handle script_url = NewString("theScript"); |
| 6124 source = NewString(kScriptChars); | 6126 source = NewString(kScriptChars); |
| 6125 Dart_Handle test_script = Dart_LoadScript(script_url, source, 0, 0); | 6127 Dart_Handle test_script = Dart_LoadScript(script_url, source, 0, 0); |
| 6126 EXPECT_VALID(test_script); | 6128 EXPECT_VALID(test_script); |
| 6127 | 6129 |
| 6128 // Make sure that we can compile all of the patched code. | 6130 // Make sure that we can compile all of the patched code. |
| 6129 result = Dart_CompileAll(); | 6131 result = Dart_CompileAll(); |
| 6130 EXPECT_VALID(result); | 6132 EXPECT_VALID(result); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6223 Dart_Handle url = NewString(TestCase::url()); | 6225 Dart_Handle url = NewString(TestCase::url()); |
| 6224 Dart_Handle source = NewString(kScriptChars); | 6226 Dart_Handle source = NewString(kScriptChars); |
| 6225 result = Dart_SetLibraryTagHandler(library_handler); | 6227 result = Dart_SetLibraryTagHandler(library_handler); |
| 6226 EXPECT_VALID(result); | 6228 EXPECT_VALID(result); |
| 6227 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); | 6229 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); |
| 6228 EXPECT_VALID(lib); | 6230 EXPECT_VALID(lib); |
| 6229 EXPECT(Dart_IsLibrary(lib)); | 6231 EXPECT(Dart_IsLibrary(lib)); |
| 6230 Dart_Handle type = Dart_GetType(lib, NewString("Test"), 0, NULL); | 6232 Dart_Handle type = Dart_GetType(lib, NewString("Test"), 0, NULL); |
| 6231 EXPECT_VALID(type); | 6233 EXPECT_VALID(type); |
| 6232 | 6234 |
| 6233 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1); | 6235 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1, NULL); |
| 6234 EXPECT(Dart_IsError(result)); | 6236 EXPECT(Dart_IsError(result)); |
| 6235 EXPECT_STREQ( | 6237 EXPECT_STREQ( |
| 6236 "Dart_SetNativeResolver expects argument 'library' to be non-null.", | 6238 "Dart_SetNativeResolver expects argument 'library' to be non-null.", |
| 6237 Dart_GetError(result)); | 6239 Dart_GetError(result)); |
| 6238 | 6240 |
| 6239 result = Dart_SetNativeResolver(Dart_True(), &MyNativeResolver1); | 6241 result = Dart_SetNativeResolver(Dart_True(), &MyNativeResolver1, NULL); |
| 6240 EXPECT(Dart_IsError(result)); | 6242 EXPECT(Dart_IsError(result)); |
| 6241 EXPECT_STREQ("Dart_SetNativeResolver expects argument 'library' to be of " | 6243 EXPECT_STREQ("Dart_SetNativeResolver expects argument 'library' to be of " |
| 6242 "type Library.", | 6244 "type Library.", |
| 6243 Dart_GetError(result)); | 6245 Dart_GetError(result)); |
| 6244 | 6246 |
| 6245 result = Dart_SetNativeResolver(error, &MyNativeResolver1); | 6247 result = Dart_SetNativeResolver(error, &MyNativeResolver1, NULL); |
| 6246 EXPECT(Dart_IsError(result)); | 6248 EXPECT(Dart_IsError(result)); |
| 6247 EXPECT_STREQ("incoming error", Dart_GetError(result)); | 6249 EXPECT_STREQ("incoming error", Dart_GetError(result)); |
| 6248 | 6250 |
| 6249 result = Dart_SetNativeResolver(lib, &MyNativeResolver1); | 6251 result = Dart_SetNativeResolver(lib, &MyNativeResolver1, NULL); |
| 6250 EXPECT_VALID(result); | 6252 EXPECT_VALID(result); |
| 6251 | 6253 |
| 6252 // Call a function and make sure native resolution works. | 6254 // Call a function and make sure native resolution works. |
| 6253 result = Dart_Invoke(type, NewString("foo"), 0, NULL); | 6255 result = Dart_Invoke(type, NewString("foo"), 0, NULL); |
| 6254 EXPECT_VALID(result); | 6256 EXPECT_VALID(result); |
| 6255 EXPECT(Dart_IsInteger(result)); | 6257 EXPECT(Dart_IsInteger(result)); |
| 6256 int64_t value = 0; | 6258 int64_t value = 0; |
| 6257 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6259 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6258 EXPECT_EQ(654321, value); | 6260 EXPECT_EQ(654321, value); |
| 6259 | 6261 |
| 6260 // A second call succeeds. | 6262 // A second call succeeds. |
| 6261 result = Dart_SetNativeResolver(lib, &MyNativeResolver2); | 6263 result = Dart_SetNativeResolver(lib, &MyNativeResolver2, NULL); |
| 6262 EXPECT_VALID(result); | 6264 EXPECT_VALID(result); |
| 6263 | 6265 |
| 6264 // 'foo' has already been resolved so gets the old value. | 6266 // 'foo' has already been resolved so gets the old value. |
| 6265 result = Dart_Invoke(type, NewString("foo"), 0, NULL); | 6267 result = Dart_Invoke(type, NewString("foo"), 0, NULL); |
| 6266 EXPECT_VALID(result); | 6268 EXPECT_VALID(result); |
| 6267 EXPECT(Dart_IsInteger(result)); | 6269 EXPECT(Dart_IsInteger(result)); |
| 6268 value = 0; | 6270 value = 0; |
| 6269 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6271 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6270 EXPECT_EQ(654321, value); | 6272 EXPECT_EQ(654321, value); |
| 6271 | 6273 |
| 6272 // 'bar' has not yet been resolved so gets the new value. | 6274 // 'bar' has not yet been resolved so gets the new value. |
| 6273 result = Dart_Invoke(type, NewString("bar"), 0, NULL); | 6275 result = Dart_Invoke(type, NewString("bar"), 0, NULL); |
| 6274 EXPECT_VALID(result); | 6276 EXPECT_VALID(result); |
| 6275 EXPECT(Dart_IsInteger(result)); | 6277 EXPECT(Dart_IsInteger(result)); |
| 6276 value = 0; | 6278 value = 0; |
| 6277 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6279 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6278 EXPECT_EQ(123456, value); | 6280 EXPECT_EQ(123456, value); |
| 6279 | 6281 |
| 6280 // A NULL resolver is okay, but resolution will fail. | 6282 // A NULL resolver is okay, but resolution will fail. |
| 6281 result = Dart_SetNativeResolver(lib, NULL); | 6283 result = Dart_SetNativeResolver(lib, NULL, NULL); |
| 6282 EXPECT_VALID(result); | 6284 EXPECT_VALID(result); |
| 6283 | 6285 |
| 6284 EXPECT_ERROR(Dart_Invoke(type, NewString("baz"), 0, NULL), | 6286 EXPECT_ERROR(Dart_Invoke(type, NewString("baz"), 0, NULL), |
| 6285 "native function 'SomeNativeFunction3' (0 arguments) " | 6287 "native function 'SomeNativeFunction3' (0 arguments) " |
| 6286 "cannot be found"); | 6288 "cannot be found"); |
| 6287 } | 6289 } |
| 6288 | 6290 |
| 6289 | 6291 |
| 6290 // Test that an imported name does not clash with the same name defined | 6292 // Test that an imported name does not clash with the same name defined |
| 6291 // in the importing library. | 6293 // in the importing library. |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6694 bin::snapshot_buffer, | 6696 bin::snapshot_buffer, |
| 6695 NULL, &error); | 6697 NULL, &error); |
| 6696 EXPECT(shared_isolate != NULL); | 6698 EXPECT(shared_isolate != NULL); |
| 6697 Dart_EnterScope(); | 6699 Dart_EnterScope(); |
| 6698 Dart_Handle url = NewString(TestCase::url()); | 6700 Dart_Handle url = NewString(TestCase::url()); |
| 6699 Dart_Handle source = NewString(kScriptChars); | 6701 Dart_Handle source = NewString(kScriptChars); |
| 6700 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); | 6702 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
| 6701 EXPECT_VALID(result); | 6703 EXPECT_VALID(result); |
| 6702 lib = Dart_LoadScript(url, source, 0, 0); | 6704 lib = Dart_LoadScript(url, source, 0, 0); |
| 6703 EXPECT_VALID(lib); | 6705 EXPECT_VALID(lib); |
| 6704 result = Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup); | 6706 result = |
| 6707 Dart_SetNativeResolver(lib, &IsolateInterruptTestNativeLookup, NULL); |
| 6705 DART_CHECK_VALID(result); | 6708 DART_CHECK_VALID(result); |
| 6706 | 6709 |
| 6707 sync->Notify(); | 6710 sync->Notify(); |
| 6708 sync->Exit(); | 6711 sync->Exit(); |
| 6709 } | 6712 } |
| 6710 | 6713 |
| 6711 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 6714 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 6712 EXPECT(Dart_IsError(result)); | 6715 EXPECT(Dart_IsError(result)); |
| 6713 EXPECT(Dart_ErrorHasException(result)); | 6716 EXPECT(Dart_ErrorHasException(result)); |
| 6714 EXPECT_SUBSTRING("Unhandled exception:\nfoo\n", | 6717 EXPECT_SUBSTRING("Unhandled exception:\nfoo\n", |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7056 Dart_Handle result; | 7059 Dart_Handle result; |
| 7057 | 7060 |
| 7058 // Load a test script. | 7061 // Load a test script. |
| 7059 Dart_Handle url = NewString(TestCase::url()); | 7062 Dart_Handle url = NewString(TestCase::url()); |
| 7060 Dart_Handle source = NewString(kScriptChars); | 7063 Dart_Handle source = NewString(kScriptChars); |
| 7061 result = Dart_SetLibraryTagHandler(library_handler); | 7064 result = Dart_SetLibraryTagHandler(library_handler); |
| 7062 EXPECT_VALID(result); | 7065 EXPECT_VALID(result); |
| 7063 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); | 7066 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); |
| 7064 EXPECT_VALID(lib); | 7067 EXPECT_VALID(lib); |
| 7065 EXPECT(Dart_IsLibrary(lib)); | 7068 EXPECT(Dart_IsLibrary(lib)); |
| 7066 result = Dart_SetNativeResolver(lib, &MyNativeClosureResolver); | 7069 result = Dart_SetNativeResolver(lib, &MyNativeClosureResolver, NULL); |
| 7067 EXPECT_VALID(result); | 7070 EXPECT_VALID(result); |
| 7068 | 7071 |
| 7069 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 7072 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 7070 EXPECT_VALID(result); | 7073 EXPECT_VALID(result); |
| 7071 EXPECT(Dart_IsInteger(result)); | 7074 EXPECT(Dart_IsInteger(result)); |
| 7072 int64_t value = 0; | 7075 int64_t value = 0; |
| 7073 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 7076 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 7074 EXPECT_EQ(0, value); | 7077 EXPECT_EQ(0, value); |
| 7075 } | 7078 } |
| 7076 | 7079 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7203 Dart_Handle result; | 7206 Dart_Handle result; |
| 7204 | 7207 |
| 7205 // Load a test script. | 7208 // Load a test script. |
| 7206 Dart_Handle url = NewString(TestCase::url()); | 7209 Dart_Handle url = NewString(TestCase::url()); |
| 7207 Dart_Handle source = NewString(kScriptChars); | 7210 Dart_Handle source = NewString(kScriptChars); |
| 7208 result = Dart_SetLibraryTagHandler(library_handler); | 7211 result = Dart_SetLibraryTagHandler(library_handler); |
| 7209 EXPECT_VALID(result); | 7212 EXPECT_VALID(result); |
| 7210 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); | 7213 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); |
| 7211 EXPECT_VALID(lib); | 7214 EXPECT_VALID(lib); |
| 7212 EXPECT(Dart_IsLibrary(lib)); | 7215 EXPECT(Dart_IsLibrary(lib)); |
| 7213 result = Dart_SetNativeResolver(lib, &MyStaticNativeClosureResolver); | 7216 result = Dart_SetNativeResolver(lib, &MyStaticNativeClosureResolver, NULL); |
| 7214 EXPECT_VALID(result); | 7217 EXPECT_VALID(result); |
| 7215 | 7218 |
| 7216 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 7219 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
| 7217 EXPECT_VALID(result); | 7220 EXPECT_VALID(result); |
| 7218 EXPECT(Dart_IsInteger(result)); | 7221 EXPECT(Dart_IsInteger(result)); |
| 7219 int64_t value = 0; | 7222 int64_t value = 0; |
| 7220 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 7223 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 7221 EXPECT_EQ(0, value); | 7224 EXPECT_EQ(0, value); |
| 7222 } | 7225 } |
| 7223 | 7226 |
| (...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8093 dart_args); | 8096 dart_args); |
| 8094 int64_t value = 0; | 8097 int64_t value = 0; |
| 8095 result = Dart_IntegerToInt64(result, &value); | 8098 result = Dart_IntegerToInt64(result, &value); |
| 8096 EXPECT_VALID(result); | 8099 EXPECT_VALID(result); |
| 8097 EXPECT_EQ(6, value); | 8100 EXPECT_EQ(6, value); |
| 8098 } | 8101 } |
| 8099 | 8102 |
| 8100 } // namespace dart | 8103 } // namespace dart |
| 8101 | 8104 |
| 8102 #endif // !defined(TARGET_ARCH_ARM64) | 8105 #endif // !defined(TARGET_ARCH_ARM64) |
| OLD | NEW |