Skip to content

Commit

Permalink
Remove the need to Array#slice over arguments in `String.{fromCod…
Browse files Browse the repository at this point in the history
…ePoint, raw}`
  • Loading branch information
ljharb committed Nov 19, 2014
1 parent 8fc65d2 commit 8743d8d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
11 changes: 4 additions & 7 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,11 @@

defineProperties(String, {
fromCodePoint: function (_) { // length = 1
var points = _slice.call(arguments, 0, arguments.length);
var result = [];
var next;
for (var i = 0, length = points.length; i < length; i++) {
next = Number(points[i]);
if (!ES.SameValue(next, ES.ToInteger(next)) ||
next < 0 || next > 0x10FFFF) {
for (var i = 0, length = arguments.length; i < length; i++) {
next = Number(arguments[i]);
if (!ES.SameValue(next, ES.ToInteger(next)) || next < 0 || next > 0x10FFFF) {
throw new RangeError('Invalid code point ' + next);
}

Expand All @@ -444,7 +442,6 @@
},

raw: function (callSite) { // raw.length===1
var substitutions = _slice.call(arguments, 1, arguments.length);
var cooked = ES.ToObject(callSite, 'bad callSite');
var rawValue = cooked.raw;
var raw = ES.ToObject(rawValue, 'bad raw value');
Expand All @@ -465,7 +462,7 @@
if (nextIndex + 1 >= literalsegments) {
break;
}
next = substitutions[nextKey];
next = arguments[nextIndex + 1];
if (typeof next === 'undefined') {
break;
}
Expand Down
8 changes: 4 additions & 4 deletions test/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,23 +385,23 @@ var runStringTests = function () {

var str = 'The total is 10 ($11 with tax)';
callSite.raw = ['The total is ', ' ($', ' with tax)'];
expect(String.raw(callSite,10,11)).to.eql(str);
expect(String.raw(callSite, 10, 11)).to.eql(str);

str = 'The total is {total} (${total * 1.01} with tax)';
callSite.raw = ['The total is ', ' ($', ' with tax)'];
expect(String.raw(callSite,'{total}','{total * 1.01}')).to.eql(str);
expect(String.raw(callSite, '{total}', '{total * 1.01}')).to.eql(str);
});

it('String.raw Works with Objects , Keys as Integer', function () {
var callSite = {};

var str = 'The total is 10 ($11 with tax)';
callSite.raw = {0: 'The total is ', 1: ' ($', 2: ' with tax)'};
expect(String.raw(callSite,10,11)).to.eql(str);
expect(String.raw(callSite, 10, 11)).to.eql(str);

str = 'The total is {total} (${total * 1.01} with tax)';
callSite.raw = {0: 'The total is ', 1: ' ($', 2: ' with tax)'};
expect(String.raw(callSite,'{total}','{total * 1.01}')).to.eql(str);
expect(String.raw(callSite, '{total}', '{total * 1.01}')).to.eql(str);
});

it('String.raw Works with Objects , Keys as String', function () {
Expand Down

0 comments on commit 8743d8d

Please sign in to comment.