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