2015-08-28 12:59:51 +00:00
|
|
|
// 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
|
|
|
|
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals("1", %ToString(1));
|
2015-08-28 12:59:51 +00:00
|
|
|
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals("0.5", %ToString(.5));
|
2015-08-28 12:59:51 +00:00
|
|
|
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals("null", %ToString(null));
|
2015-08-28 12:59:51 +00:00
|
|
|
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals("true", %ToString(true));
|
2015-08-28 12:59:51 +00:00
|
|
|
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals("false", %ToString(false));
|
2015-08-28 12:59:51 +00:00
|
|
|
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals("undefined", %ToString(undefined));
|
2015-08-28 12:59:51 +00:00
|
|
|
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals("random text", %ToString("random text"));
|
2015-08-28 12:59:51 +00:00
|
|
|
|
2020-09-25 20:29:34 +00:00
|
|
|
assertThrows(function() { %ToString(Symbol.toPrimitive) }, TypeError);
|
2015-08-28 12:59:51 +00:00
|
|
|
|
|
|
|
var a = { toString: function() { return "xyz" }};
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals("xyz", %ToString(a));
|
2015-08-28 12:59:51 +00:00
|
|
|
|
|
|
|
var b = { valueOf: function() { return 42 }};
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals("[object Object]", %ToString(b));
|
2015-08-28 12:59:51 +00:00
|
|
|
|
|
|
|
var c = {
|
|
|
|
toString: function() { return "x"},
|
|
|
|
valueOf: function() { return 123 }
|
|
|
|
};
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals("x", %ToString(c));
|
2015-08-28 12:59:51 +00:00
|
|
|
|
|
|
|
var d = {
|
|
|
|
[Symbol.toPrimitive]: function(hint) { return hint }
|
|
|
|
};
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals("string", %ToString(d));
|
2015-08-31 12:52:59 +00:00
|
|
|
|
|
|
|
var e = new Date(0);
|
2020-09-25 20:29:34 +00:00
|
|
|
assertEquals(e.toString(), %ToString(e));
|