| 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/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
| 7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "platform/json.h" | 10 #include "platform/json.h" |
| (...skipping 7061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7072 | 7072 |
| 7073 // Shutdown the isolate. | 7073 // Shutdown the isolate. |
| 7074 Dart_ShutdownIsolate(); | 7074 Dart_ShutdownIsolate(); |
| 7075 | 7075 |
| 7076 // The shutdown callback has been called. | 7076 // The shutdown callback has been called. |
| 7077 EXPECT_EQ(12345, reinterpret_cast<intptr_t>(saved_callback_data)); | 7077 EXPECT_EQ(12345, reinterpret_cast<intptr_t>(saved_callback_data)); |
| 7078 | 7078 |
| 7079 Isolate::SetShutdownCallback(saved); | 7079 Isolate::SetShutdownCallback(saved); |
| 7080 } | 7080 } |
| 7081 | 7081 |
| 7082 static int64_t add_result = 0; |
| 7083 static void IsolateShutdownRunDartCodeTestCallback(void* callback_data) { |
| 7084 Dart_EnterScope(); |
| 7085 Dart_Handle lib = Dart_RootLibrary(); |
| 7086 EXPECT_VALID(lib); |
| 7087 Dart_Handle arg1 = Dart_NewInteger(90); |
| 7088 EXPECT_VALID(arg1); |
| 7089 Dart_Handle arg2 = Dart_NewInteger(9); |
| 7090 EXPECT_VALID(arg2); |
| 7091 Dart_Handle dart_args[2] = { arg1, arg2 }; |
| 7092 Dart_Handle result = Dart_Invoke(lib, NewString("add"), 2, dart_args); |
| 7093 EXPECT_VALID(result); |
| 7094 result = Dart_IntegerToInt64(result, &add_result); |
| 7095 EXPECT_VALID(result); |
| 7096 Dart_ExitScope(); |
| 7097 } |
| 7098 |
| 7099 UNIT_TEST_CASE(IsolateShutdownRunDartCode) { |
| 7100 const char* kScriptChars = |
| 7101 "int add(int a, int b) {\n" |
| 7102 " return a + b;\n" |
| 7103 "}\n" |
| 7104 "\n" |
| 7105 "void main() {\n" |
| 7106 " add(4, 5);\n" |
| 7107 "}\n"; |
| 7108 |
| 7109 // Create an isolate. |
| 7110 char* err; |
| 7111 Dart_Isolate isolate = Dart_CreateIsolate(NULL, NULL, |
| 7112 bin::snapshot_buffer, |
| 7113 NULL, &err); |
| 7114 if (isolate == NULL) { |
| 7115 OS::Print("Creation of isolate failed '%s'\n", err); |
| 7116 free(err); |
| 7117 } |
| 7118 EXPECT(isolate != NULL); |
| 7119 |
| 7120 Isolate::SetShutdownCallback(IsolateShutdownRunDartCodeTestCallback); |
| 7121 |
| 7122 { |
| 7123 Dart_EnterScope(); |
| 7124 Dart_Handle url = NewString(TestCase::url()); |
| 7125 Dart_Handle source = NewString(kScriptChars); |
| 7126 Dart_Handle result = Dart_SetLibraryTagHandler(TestCase::library_handler); |
| 7127 EXPECT_VALID(result); |
| 7128 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); |
| 7129 EXPECT_VALID(lib); |
| 7130 result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 7131 EXPECT_VALID(result); |
| 7132 Dart_ExitScope(); |
| 7133 } |
| 7134 |
| 7135 |
| 7136 // The shutdown callback has not been called. |
| 7137 EXPECT_EQ(0, add_result); |
| 7138 |
| 7139 EXPECT(isolate != NULL); |
| 7140 |
| 7141 // Shutdown the isolate. |
| 7142 Dart_ShutdownIsolate(); |
| 7143 |
| 7144 // The shutdown callback has been called and ran Dart code. |
| 7145 EXPECT_EQ(99, add_result); |
| 7146 } |
| 7147 |
| 7082 static int64_t GetValue(Dart_Handle arg) { | 7148 static int64_t GetValue(Dart_Handle arg) { |
| 7083 EXPECT_VALID(arg); | 7149 EXPECT_VALID(arg); |
| 7084 EXPECT(Dart_IsInteger(arg)); | 7150 EXPECT(Dart_IsInteger(arg)); |
| 7085 int64_t value; | 7151 int64_t value; |
| 7086 EXPECT_VALID(Dart_IntegerToInt64(arg, &value)); | 7152 EXPECT_VALID(Dart_IntegerToInt64(arg, &value)); |
| 7087 return value; | 7153 return value; |
| 7088 } | 7154 } |
| 7089 | 7155 |
| 7090 static void NativeFoo1(Dart_NativeArguments args) { | 7156 static void NativeFoo1(Dart_NativeArguments args) { |
| 7091 Dart_EnterScope(); | 7157 Dart_EnterScope(); |
| (...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8142 NewString("main"), | 8208 NewString("main"), |
| 8143 0, | 8209 0, |
| 8144 NULL); | 8210 NULL); |
| 8145 int64_t value = 0; | 8211 int64_t value = 0; |
| 8146 result = Dart_IntegerToInt64(result, &value); | 8212 result = Dart_IntegerToInt64(result, &value); |
| 8147 EXPECT_VALID(result); | 8213 EXPECT_VALID(result); |
| 8148 EXPECT_EQ(8, value); | 8214 EXPECT_EQ(8, value); |
| 8149 } | 8215 } |
| 8150 | 8216 |
| 8151 } // namespace dart | 8217 } // namespace dart |
| OLD | NEW |