OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/report.h" | 6 #include "vm/report.h" |
7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 | 10 |
11 TEST_CASE(TraceJSWarning) { | 11 TEST_CASE(TraceJSWarning) { |
12 Zone* zone = thread->zone(); | 12 Zone* zone = thread->zone(); |
13 Isolate* isolate = thread->isolate(); | 13 Isolate* isolate = thread->isolate(); |
14 TraceBuffer::Init(isolate, 3); | 14 TraceBuffer::Init(isolate, 3); |
15 TraceBuffer* trace_buffer = isolate->trace_buffer(); | 15 TraceBuffer* trace_buffer = isolate->trace_buffer(); |
16 const String& url = String::Handle(zone, String::New("Plug")); | 16 const String& url = String::Handle(zone, String::New("Plug")); |
17 const String& source = String::Handle(zone, String::New("240 100")); | 17 const String& source = String::Handle(zone, String::New("240 100")); |
18 const Script& script = Script::Handle(zone, | 18 const Script& script = Script::Handle(zone, |
19 Script::New(url, source, RawScript::kEvaluateTag)); | 19 Script::New(url, source, RawScript::kEvaluateTag)); |
20 script.Tokenize(String::Handle(String::New(""))); | 20 script.Tokenize(String::Handle(String::New(""))); |
21 { | 21 { |
22 const intptr_t token_pos = 0; | 22 const TokenPosition token_pos = TokenPosition(0); |
23 const char* message = "High Voltage"; | 23 const char* message = "High Voltage"; |
24 Report::MessageF(Report::kJSWarning, | 24 Report::MessageF(Report::kJSWarning, |
25 script, token_pos, Report::AtLocation, "%s", message); | 25 script, token_pos, Report::AtLocation, "%s", message); |
26 { | 26 { |
27 JSONStream js; | 27 JSONStream js; |
28 trace_buffer->PrintToJSONStream(&js); | 28 trace_buffer->PrintToJSONStream(&js); |
29 EXPECT_SUBSTRING("{\"type\":\"TraceBuffer\",\"members\":[" | 29 EXPECT_SUBSTRING("{\"type\":\"TraceBuffer\",\"members\":[" |
30 "{\"type\":\"TraceBufferEntry\",\"time\":", | 30 "{\"type\":\"TraceBufferEntry\",\"time\":", |
31 js.ToCString()); | 31 js.ToCString()); |
32 // Skip time. | 32 // Skip time. |
33 EXPECT_SUBSTRING("\"message\":{\"type\":\"JSCompatibilityWarning\"," | 33 EXPECT_SUBSTRING("\"message\":{\"type\":\"JSCompatibilityWarning\"," |
34 "\"script\":{\"type\":\"@Script\"", | 34 "\"script\":{\"type\":\"@Script\"", |
35 js.ToCString()); | 35 js.ToCString()); |
36 // Skip object ring id. | 36 // Skip object ring id. |
37 EXPECT_SUBSTRING("\"uri\":\"Plug\"," | 37 EXPECT_SUBSTRING("\"uri\":\"Plug\"," |
38 "\"_kind\":\"evaluate\"},\"tokenPos\":0," | 38 "\"_kind\":\"evaluate\"},\"tokenPos\":0," |
39 "\"message\":{\"type\":\"@Instance\"", | 39 "\"message\":{\"type\":\"@Instance\"", |
40 js.ToCString()); | 40 js.ToCString()); |
41 // Skip private _OneByteString. | 41 // Skip private _OneByteString. |
42 EXPECT_SUBSTRING("\"valueAsString\":\"High Voltage\"", | 42 EXPECT_SUBSTRING("\"valueAsString\":\"High Voltage\"", |
43 js.ToCString()); | 43 js.ToCString()); |
44 } | 44 } |
45 } | 45 } |
46 { | 46 { |
47 const intptr_t token_pos = 1; | 47 const TokenPosition token_pos = TokenPosition(1); |
48 const char* message = "Low Voltage"; | 48 const char* message = "Low Voltage"; |
49 Report::MessageF(Report::kJSWarning, | 49 Report::MessageF(Report::kJSWarning, |
50 script, token_pos, Report::AtLocation, "%s", message); | 50 script, token_pos, Report::AtLocation, "%s", message); |
51 } | 51 } |
52 EXPECT_EQ(2, trace_buffer->Length()); | 52 EXPECT_EQ(2, trace_buffer->Length()); |
53 EXPECT_SUBSTRING("{\"type\":\"JSCompatibilityWarning\",\"script\":{\"type\":" | 53 EXPECT_SUBSTRING("{\"type\":\"JSCompatibilityWarning\",\"script\":{\"type\":" |
54 "\"@Script\"", | 54 "\"@Script\"", |
55 trace_buffer->At(0)->message); | 55 trace_buffer->At(0)->message); |
56 // Skip object ring id. | 56 // Skip object ring id. |
57 EXPECT_SUBSTRING("\"uri\":\"Plug\"," | 57 EXPECT_SUBSTRING("\"uri\":\"Plug\"," |
(...skipping 13 matching lines...) Expand all Loading... |
71 "\"message\":{\"type\":\"@Instance\"", | 71 "\"message\":{\"type\":\"@Instance\"", |
72 trace_buffer->At(1)->message); | 72 trace_buffer->At(1)->message); |
73 // Skip private _OneByteString. | 73 // Skip private _OneByteString. |
74 EXPECT_SUBSTRING("\"valueAsString\":\"Low Voltage\"", | 74 EXPECT_SUBSTRING("\"valueAsString\":\"Low Voltage\"", |
75 trace_buffer->At(1)->message); | 75 trace_buffer->At(1)->message); |
76 | 76 |
77 delete trace_buffer; | 77 delete trace_buffer; |
78 } | 78 } |
79 | 79 |
80 } // namespace dart | 80 } // namespace dart |
OLD | NEW |