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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-object.cc
diff --git a/test/cctest/test-object.cc b/test/cctest/test-object.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e078bfcdb06f2c01dfc95f25444946ec109c243c
--- /dev/null
+++ b/test/cctest/test-object.cc
@@ -0,0 +1,71 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/v8.h"
+
+#include "test/cctest/cctest.h"
+
+using namespace v8::internal;
+
+static void CheckObject(Isolate* isolate, Handle<Object> obj,
+ const char* string) {
+ Object* print_string = *Object::NoSideEffectsToString(isolate, obj);
+ CHECK(String::cast(print_string)->IsUtf8EqualTo(CStrVector(string)));
+}
+
+static void CheckSmi(Isolate* isolate, int value, const char* string) {
+ Handle<Object> handle(Smi::FromInt(value), isolate);
+ CheckObject(isolate, handle, string);
+}
+
+static void CheckString(Isolate* isolate, const char* value,
+ const char* string) {
+ Handle<String> handle(isolate->factory()->NewStringFromAsciiChecked(value));
+ CheckObject(isolate, handle, string);
+}
+
+static void CheckNumber(Isolate* isolate, double value, const char* string) {
+ Handle<Object> number = isolate->factory()->NewNumber(value);
+ CHECK(number->IsNumber());
+ CheckObject(isolate, number, string);
+}
+
+static void CheckBoolean(Isolate* isolate, bool value, const char* string) {
+ CheckObject(isolate, value ? isolate->factory()->true_value()
+ : isolate->factory()->false_value(),
+ string);
+}
+
+TEST(NoSideEffectsToString) {
+ CcTest::InitializeVM();
+ Isolate* isolate = CcTest::i_isolate();
+ Factory* factory = isolate->factory();
+
+ HandleScope scope(isolate);
+
+ CheckString(isolate, "fisk hest", "fisk hest");
+ CheckNumber(isolate, 42.3, "42.3");
+ CheckSmi(isolate, 42, "42");
+ CheckBoolean(isolate, true, "true");
+ CheckBoolean(isolate, false, "false");
+ CheckBoolean(isolate, false, "false");
+ CheckObject(isolate, factory->undefined_value(), "undefined");
+ CheckObject(isolate, factory->null_value(), "null");
+
+ int lanes[] = {0, 1, 2, 3};
+ CheckObject(isolate, factory->NewInt32x4(lanes), "SIMD.Int32x4(0, 1, 2, 3)");
+
+ CheckObject(isolate, factory->error_to_string(), "[object Error]");
+ CheckObject(isolate, factory->stack_trace_symbol(),
+ "Symbol(stack_trace_symbol)");
+ CheckObject(isolate, factory->NewError(isolate->error_function(),
+ factory->empty_string()),
+ "Error");
+ CheckObject(isolate, factory->NewError(
+ isolate->error_function(),
+ factory->NewStringFromAsciiChecked("fisk hest")),
+ "Error: fisk hest");
+ CheckObject(isolate, factory->NewJSObject(isolate->object_function()),
+ "#<Object>");
+}
« 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