| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
*/ |
| 4 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 7 |
|
| 8 |
#include "jsapi-tests/tests.h" |
| 9 |
|
| 10 |
BEGIN_TEST(testIntString_bug515273) { |
| 11 |
JS::RootedValue v(cx); |
| 12 |
|
| 13 |
EVAL("'1';", &v); |
| 14 |
JSString* str = v.toString(); |
| 15 |
CHECK(JS_StringHasBeenPinned(cx, str)); |
| 16 |
CHECK(JS_LinearStringEqualsLiteral(JS_ASSERT_STRING_IS_LINEAR(str), "1")); |
| 17 |
|
| 18 |
EVAL("'42';", &v); |
| 19 |
str = v.toString(); |
| 20 |
CHECK(JS_StringHasBeenPinned(cx, str)); |
| 21 |
CHECK(JS_LinearStringEqualsLiteral(JS_ASSERT_STRING_IS_LINEAR(str), "42")); |
| 22 |
|
| 23 |
// Short string literal should use atom. |
| 24 |
EVAL("'111';", &v); |
| 25 |
str = v.toString(); |
| 26 |
CHECK(JS_StringHasBeenPinned(cx, str)); |
| 27 |
CHECK(JS_LinearStringEqualsLiteral(JS_ASSERT_STRING_IS_LINEAR(str), "111")); |
| 28 |
|
| 29 |
// Long string literal shouldn't use atom, but just linear string. |
| 30 |
EVAL("'111222333';", &v); |
| 31 |
str = v.toString(); |
| 32 |
CHECK(!JS_StringHasBeenPinned(cx, str)); |
| 33 |
CHECK(JS_LinearStringEqualsLiteral(JS_ASSERT_STRING_IS_LINEAR(str), |
| 34 |
"111222333")); |
| 35 |
|
| 36 |
/* Test other types of static strings. */ |
| 37 |
EVAL("'a';", &v); |
| 38 |
str = v.toString(); |
| 39 |
CHECK(JS_StringHasBeenPinned(cx, str)); |
| 40 |
CHECK(JS_LinearStringEqualsLiteral(JS_ASSERT_STRING_IS_LINEAR(str), "a")); |
| 41 |
|
| 42 |
EVAL("'bc';", &v); |
| 43 |
str = v.toString(); |
| 44 |
CHECK(JS_StringHasBeenPinned(cx, str)); |
| 45 |
CHECK(JS_LinearStringEqualsLiteral(JS_ASSERT_STRING_IS_LINEAR(str), "bc")); |
| 46 |
|
| 47 |
return true; |
| 48 |
} |
| 49 |
END_TEST(testIntString_bug515273) |