Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1021)

Side by Side Diff: test/cctest/test-object.cc

Issue 2206573002: Move NoSideEffectToString to C++ (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/mjsunit/regress/regress-crbug-492526.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "test/cctest/cctest.h"
8
9 using namespace v8::internal;
10
11 static void CheckObject(Isolate* isolate, Handle<Object> obj,
12 const char* string) {
13 Object* print_string = *Object::NoSideEffectsToString(isolate, obj);
14 CHECK(String::cast(print_string)->IsUtf8EqualTo(CStrVector(string)));
15 }
16
17 static void CheckSmi(Isolate* isolate, int value, const char* string) {
18 Handle<Object> handle(Smi::FromInt(value), isolate);
19 CheckObject(isolate, handle, string);
20 }
21
22 static void CheckString(Isolate* isolate, const char* value,
23 const char* string) {
24 Handle<String> handle(isolate->factory()->NewStringFromAsciiChecked(value));
25 CheckObject(isolate, handle, string);
26 }
27
28 static void CheckNumber(Isolate* isolate, double value, const char* string) {
29 Handle<Object> number = isolate->factory()->NewNumber(value);
30 CHECK(number->IsNumber());
31 CheckObject(isolate, number, string);
32 }
33
34 static void CheckBoolean(Isolate* isolate, bool value, const char* string) {
35 CheckObject(isolate, value ? isolate->factory()->true_value()
36 : isolate->factory()->false_value(),
37 string);
38 }
39
40 TEST(NoSideEffectsToString) {
41 CcTest::InitializeVM();
42 Isolate* isolate = CcTest::i_isolate();
43 Factory* factory = isolate->factory();
44
45 HandleScope scope(isolate);
46
47 CheckString(isolate, "fisk hest", "fisk hest");
48 CheckNumber(isolate, 42.3, "42.3");
49 CheckSmi(isolate, 42, "42");
50 CheckBoolean(isolate, true, "true");
51 CheckBoolean(isolate, false, "false");
52 CheckBoolean(isolate, false, "false");
53 CheckObject(isolate, factory->undefined_value(), "undefined");
54 CheckObject(isolate, factory->null_value(), "null");
55
56 int lanes[] = {0, 1, 2, 3};
57 CheckObject(isolate, factory->NewInt32x4(lanes), "SIMD.Int32x4(0, 1, 2, 3)");
58
59 CheckObject(isolate, factory->error_to_string(), "[object Error]");
60 CheckObject(isolate, factory->stack_trace_symbol(),
61 "Symbol(stack_trace_symbol)");
62 CheckObject(isolate, factory->NewError(isolate->error_function(),
63 factory->empty_string()),
64 "Error");
65 CheckObject(isolate, factory->NewError(
66 isolate->error_function(),
67 factory->NewStringFromAsciiChecked("fisk hest")),
68 "Error: fisk hest");
69 CheckObject(isolate, factory->NewJSObject(isolate->object_function()),
70 "#<Object>");
71 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/mjsunit/regress/regress-crbug-492526.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698