paulmillr / es6-shim Goto Github PK
View Code? Open in Web Editor NEWECMAScript 6 compatibility shims for legacy JS engines
Home Page: http://paulmillr.com
License: MIT License
ECMAScript 6 compatibility shims for legacy JS engines
Home Page: http://paulmillr.com
License: MIT License
From the - http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.5.4.21
NOTE 2 The repeat function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method.
So if i do
var k = 2;
k.repeat(3) , is this should result in 222 ?
Would be really nice to have lodash-like custom builds, I guess. Some people need only 1-3 functions from here.
String.prototype.reverse
Array.prototype.contains
https://mail.mozilla.org/pipermail/es-discuss/2012-March/021919.html
?
seems,
denormalized number are not supported on iPad, so
and Number.MIN_VALUE is buggy ( === 0)
because of this, many tests from #85 fails on iPad
according to ES6 (not ES5!) spec, http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.7.3.3
In the IEEE-764 double precision binary representation, the smallest possible value is a denormalized number. If an implementation does not support denormalized values, the value of Number.MIN_VALUE must be the smallest non-zero positive value that can actually be represented by the implementation.
so, can you shim Number.MIN_VALUE ?
seems, not, because it is not configurable...
but other value should be used for tests:
var MIN_VALUE = Number.MIN_VALUE === 0 ? 2.2250738585072014e-308 : Number.MIN_VALUE; // smallest normalized value
Browsing the code of test/index.html
saw these links -
script src="../node_modules/mocha/mocha.js"
script src="../node_modules/chai/chai.js"
script src="../node_modules/es5-shim/es5-shim.min.js"
script src="../es6-shim.js"
but Node_modules are not there in main source folder ? Not sure if this is a problem ?
Missing :- substitutions is a well-formed rest parameter object.
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.5.3.4
According to the EcmaScript6 draft specification (as well as examples on various random websites), Map.prototype.keys
is a function that takes no arguments and returns an array; when using this "shim" keys
is instead a field of a map that directly stores the array. The result means that coding against this shim will not actually be compatible with an official implementation of Map.
Shim doesn't work on my Internet Explorer 8 - 8.0.6001.18702IS on Windows XP.
The error message translated into English would be "Object doesn't have such property or method".
Looks like Object.keys
is undefined here.
>>Object.keys
undefined
I'm using the latest version, directly from master.
Let me know if you need more information. I'll be happy to provide it.
according to spec
http://people.mozilla.org/~jorendorff/es6-draft.html
Is it possible to provide a minified version as well, that way I can just bower to install the minified version.
I'm interested in es6, but I don't know how to use es6-shim.
Is there any example(simple one is enough)?
> Math.sign(-0)
0
Would you take a patch to add imperfectly shimmable features (a la WeakMap) in an es6-sham.js module? This is how Kris Kowal's refactored es5-shim and it makes a lot of sense. I understand why you don't want it in es6-shim proper but WeakMap is very shimmable regardless.
According to testling, es6-shim isn't working on IE 9. The es5-shim works there, so in theory we should work on IE 9, too.
This should be adapted & rewritten for es6-shim.
Also it doesn't seem to test weak map gc properly. I don't know how to do this automatically.
The implementation given is actually a casual version of Array.from
and the tests you wrote are also incorrectly testing Array.of
as though it were Array.from
Example of correct behaviour:
Array.of( 1, 2, 3 );
// [ 1, 2, 3 ];
There are tests that assert:
Array.of( arguments ) === [];
... which is incorrect. That would be correct for Array.from( arguments )
; Array.of( arguments )
should actually return [ arguments ]
;
Missing :- Assert: codePoints is a well-formed rest parameter object.
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.5.3.3
Chrome has probably O(log(n)) access time etc.
Math.log10(1e15) is 14.999999999999996 in Chrome 19
=> should be >=, I believe. (This is not the fat-arrow operator already, right?)
Despite loading the ES6 shim, FF's Map prototype is not aligned with the shim's Map prototype--at the very least, it's missing forEach.
es6 shim's defineProperties method looks correct to me, but I have not had time to properly debug it or even determine if that is the actual problem.
MDN examples etc
The Node.js implementation in harmony mode of Map and Set offers no way to iterate over the items (at current stage, 0.8.15) so if I accidentally use it with the es6-shim enabled it will break if I run the same code in --harmony mode.
This difference just made my life more difficult, I think it would help other devs too if it was made sure to not occur.
SameValueZero should be used as comparator according to latest spec, but is it worth to follow?
current:
startsWith: function(substring) {
return this.indexOf(substring) === 0;
},
endsWith: function(substring) {
var substr = String(substring);
var index = this.lastIndexOf(substr)
return index >= 0 && index === this.length - substr.length;
},
suggestion:
startsWith: function(substring) {
return this.lastIndexOf(substring, 0) === 0;
},
endsWith: function(substring) {
substring = String(substring);
var d = this.length - substring.length;
return d >= 0 && this.indexOf(substring, d) === d;
},
Object.defineProperty isn't shimmable in ES3, which makes the entire ES6 shim only usable in an ES5 environment.
Any shimmable parts of ES6 that do not rely on unshimmable parts of ES5 should use ES3-compatible syntax, to maximize its browser compatibility. If there are shimmable parts of ES6 that require a true ES5 environment, ideally those would be in a separate component/file.
test cases:
Math.expm1(-38) should be -1,
current result is -183115516321770.7
Math.expm1(709) should be near 8.218407461554972e+307,
current result is 8.484265749165578e+76
They seem to be missing.
require.js is looking for simple calls to define statically, it can't assume any method call to define on an arbitrary object is calling its define.
just FYI, thanks for the shim!
NOTE Each key is visited only once with the value that is current at the time of the visit. If the value associated with a
key is modified after it has been visited, it is not re-visited. Keys that are deleted after the call to forEach begins and
before being visited are not visited. New keys added, after the call to forEach begins are visited.
The following assertions for Map
fail in Firefox:
expect(map.keys).to.be.an.instanceof(Function);
expect(map.values).to.be.an.instanceof(Function);
map.keys
/map.values
appear to be undefined
The following assertion for Set
fails in Firefox:
expect(set.size).to.equal(2);
set.size
appears to be a function rather than a number.
P.S. this is the cause of the red cross in #32
http://wiki.ecmascript.org/doku.php?id=harmony:more_math_functions
Proposed are: Math.log10, log2, log1p, expm1, cosh, sinh, tanh, acosh, asinh, atanh, hypot, trunc; perhaps gamma and erf; and perhaps randomInt(n).
The current implementation is O(N) for most Map/Set operations.
should be Infinity
I think that worrying about index.html for tests is a problem. It forces, in particular, relying on a global "expect" to be set (that test_helpers sets for command-line). It makes testling tests fail, and I can only assume jepso tests as well.
I think that it would be better to eliminate the HTML entirely, or at least, use browserify to output all the JS for the html file (and store it in the repo if necessary). That way, the tests could be tweaked to only work in a node environment, but the html file would still be usable if someone wanted it (although I'm not sure why they would).
Thoughts?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.