mirror of
https://github.com/nodejs/node.git
synced 2025-05-21 12:25:12 +00:00

PR-URL: https://github.com/nodejs/node/pull/38990 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
// Copyright 2015 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.
|
|
|
|
// Flags: --allow-natives-syntax
|
|
|
|
assertEquals("1", %ToString(1));
|
|
|
|
assertEquals("0.5", %ToString(.5));
|
|
|
|
assertEquals("null", %ToString(null));
|
|
|
|
assertEquals("true", %ToString(true));
|
|
|
|
assertEquals("false", %ToString(false));
|
|
|
|
assertEquals("undefined", %ToString(undefined));
|
|
|
|
assertEquals("random text", %ToString("random text"));
|
|
|
|
assertThrows(function() { %ToString(Symbol.toPrimitive) }, TypeError);
|
|
|
|
var a = { toString: function() { return "xyz" }};
|
|
assertEquals("xyz", %ToString(a));
|
|
|
|
var b = { valueOf: function() { return 42 }};
|
|
assertEquals("[object Object]", %ToString(b));
|
|
|
|
var c = {
|
|
toString: function() { return "x"},
|
|
valueOf: function() { return 123 }
|
|
};
|
|
assertEquals("x", %ToString(c));
|
|
|
|
var d = {
|
|
[Symbol.toPrimitive]: function(hint) { return hint }
|
|
};
|
|
assertEquals("string", %ToString(d));
|
|
|
|
var e = new Date(0);
|
|
assertEquals(e.toString(), %ToString(e));
|