return true;
}
break;
+ case kStringFromCharCode:
+ if (argument_count == 2 && check_type == RECEIVER_MAP_CHECK) {
+ AddCheckConstantFunction(expr->holder(), receiver, receiver_map);
+ HValue* argument = Pop();
+ HValue* context = environment()->LookupContext();
+ Drop(1); // Receiver.
+ HInstruction* result =
+ HStringCharFromCode::New(zone(), context, argument);
+ ast_context()->ReturnInstruction(result, expr->id());
+ return true;
+ }
+ break;
case kMathExp:
if (!FLAG_fast_math) break;
// Fall through if FLAG_fast_math.
MUST_USE_RESULT static MaybeObject* CharFromCode(Isolate* isolate,
Object* char_code) {
- uint32_t code;
- if (char_code->ToArrayIndex(&code)) {
- if (code <= 0xffff) {
- return isolate->heap()->LookupSingleCharacterStringFromCode(code);
- }
+ if (char_code->IsNumber()) {
+ return isolate->heap()->LookupSingleCharacterStringFromCode(
+ NumberToUint32(char_code) & 0xffff);
}
return isolate->heap()->empty_string();
}
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Flags: --allow-natives-syntax
+
// Test String.fromCharCode.
+// Test char codes larger than 0xffff.
+var expected = "";
+for (var i = 100; i < 500; i++) {
+ expected += String.fromCharCode(i);
+}
+
+function testCharCodeTruncation() {
+ var result = "";
+ for (var i = 0x100000 + 100; i < 0x100000 + 500; i++) {
+ result += String.fromCharCode(i);
+ }
+ assertEquals(String.fromCharCode(0xFFFF), String.fromCharCode(0xFFFFFFFF));
+ return result;
+}
+
+assertEquals(expected, testCharCodeTruncation());
+assertEquals(expected, testCharCodeTruncation());
+%OptimizeFunctionOnNextCall(testCharCodeTruncation);
+assertEquals(expected, testCharCodeTruncation());
// Test various receivers and arguments passed to String.fromCharCode.