Index: runtime/vm/exceptions_test.cc |
=================================================================== |
--- runtime/vm/exceptions_test.cc (revision 37297) |
+++ runtime/vm/exceptions_test.cc (working copy) |
@@ -132,4 +132,52 @@ |
EXPECT_VALID(Dart_Invoke(lib, NewString("testMain"), 0, NULL)); |
} |
+ |
+TEST_CASE(TraceJSWarning) { |
+ Isolate* isolate = Isolate::Current(); |
+ TraceBuffer::Init(isolate, 3); |
+ TraceBuffer* trace_buffer = isolate->trace_buffer(); |
+ const String& url = String::Handle(isolate, String::New("Plug")); |
+ const String& source = String::Handle(isolate, String::New("240V")); |
+ const Script& script = Script::Handle(isolate, |
+ Script::New(url, source, RawScript::kScriptTag)); |
+ { |
+ const intptr_t token_pos = 0; |
+ const char* message = "High Voltage"; |
+ Exceptions::TraceJSWarningF(script, token_pos, "%s", message); |
+ { |
+ JSONStream js; |
+ trace_buffer->PrintToJSONStream(&js); |
+ EXPECT_SUBSTRING("{\"type\":\"TraceBuffer\",\"members\":[" |
+ "{\"type\":\"TraceBufferEntry\",\"time\":", |
+ js.ToCString()); |
+ // Skip time. |
+ EXPECT_SUBSTRING("\"message\":{\"type\":\"JSCompatibilityWarning\"," |
+ "\"script\":{\"type\":\"@Script\",\"id\":" |
+ "\"scripts\\/Plug\",\"name\":\"Plug\",\"user_name\":" |
+ "\"Plug\",\"kind\":\"script\"},\"tokenPos\":0," |
+ "\"message\":\"High Voltage\"}}]}", |
+ js.ToCString()); |
+ } |
+ } |
+ { |
+ const intptr_t token_pos = 1; |
+ const char* message = "Low Voltage"; |
+ Exceptions::TraceJSWarningF(script, token_pos, "%s", message); |
+ } |
+ EXPECT_EQ(2, trace_buffer->Length()); |
+ EXPECT_STREQ("{\"type\":\"JSCompatibilityWarning\",\"script\":{\"type\":" |
+ "\"@Script\",\"id\":\"scripts\\/Plug\",\"name\":\"Plug\"," |
+ "\"user_name\":\"Plug\",\"kind\":\"script\"},\"tokenPos\":0," |
+ "\"message\":\"High Voltage\"}", |
+ trace_buffer->At(0)->message); |
+ EXPECT_STREQ("{\"type\":\"JSCompatibilityWarning\",\"script\":{\"type\":" |
+ "\"@Script\",\"id\":\"scripts\\/Plug\",\"name\":\"Plug\"," |
+ "\"user_name\":\"Plug\",\"kind\":\"script\"},\"tokenPos\":1," |
+ "\"message\":\"Low Voltage\"}", |
+ trace_buffer->At(1)->message); |
+ |
+ delete trace_buffer; |
+} |
+ |
} // namespace dart |