-
Notifications
You must be signed in to change notification settings - Fork 50.5k
Remove React's dependency on es5-sham.js. #4192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| * Copyright 2014-2015, Facebook, Inc. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. An additional grant | ||
| * of patent rights can be found in the PATENTS file in the same directory. | ||
| * | ||
| * @providesModule Object.create | ||
| */ | ||
|
|
||
| // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.create | ||
|
|
||
| 'use strict'; | ||
|
|
||
| var nativeCreate = typeof Object.create === 'function' && Object.create; | ||
|
|
||
| var Type = function() {}; | ||
|
|
||
| function create(prototype, properties) { | ||
| if (prototype == null) { | ||
| throw new TypeError('This create() implementation cannot create empty objects with create(null)'); | ||
| } | ||
|
|
||
| if (typeof prototype !== 'object' && typeof prototype !== 'function') { | ||
| throw new TypeError('Object prototype may only be an Object'); | ||
| } | ||
|
|
||
| if (properties) { | ||
| throw new TypeError('This create() implementation does not support assigning properties'); | ||
| } | ||
|
|
||
| var object; | ||
| if ( nativeCreate ) { | ||
| object = nativeCreate(prototype); | ||
| } else { | ||
| Type.prototype = prototype; | ||
| object = new Type(); | ||
| Type.prototype = null; | ||
| } | ||
|
|
||
| return object; | ||
| } | ||
|
|
||
| module.exports = create; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /** | ||
| * Copyright 2014-2015, Facebook, Inc. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. An additional grant | ||
| * of patent rights can be found in the PATENTS file in the same directory. | ||
| * | ||
| * @providesModule Object.freeze | ||
| */ | ||
|
|
||
| // http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.9 | ||
| // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.freeze | ||
|
|
||
| 'use strict'; | ||
|
|
||
| var nativeFreeze = typeof Object.freeze === 'function' && Object.freeze; | ||
|
|
||
| function freeze(object) { | ||
| // ES5 and ES6 have different behaviors when object is not an Object. | ||
| // - ES5 Throw a TypeError | ||
| // - ES6 Return object | ||
| // Within React, using freeze() on a non-object is most likely to be an error | ||
| // so this method throws. | ||
| if (Object(object) !== object) { | ||
| throw new TypeError('freeze can only be called an Object'); | ||
| } | ||
|
|
||
| // Freeze if possible, but don't error if it is not implemented. | ||
| if (nativeFreeze) { | ||
| nativeFreeze(object); | ||
| } | ||
|
|
||
| return object; | ||
| } | ||
|
|
||
| module.exports = freeze; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| /** | ||
| * Copyright 2013-2015, Facebook, Inc. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. An additional grant | ||
| * of patent rights can be found in the PATENTS file in the same directory. | ||
| * | ||
| * @emails react-core | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| require('mock-modules') | ||
| .dontMock('Object.create'); | ||
|
|
||
| var create; | ||
|
|
||
| describe('Object.create', function() { | ||
|
|
||
| beforeEach(function() { | ||
| create = require('Object.create'); | ||
| }); | ||
|
|
||
| it('should throw when the prototype is null', function() { | ||
| expect(function() { | ||
| create(null); | ||
| }).toThrow( | ||
| 'This create() implementation cannot create empty objects with create(null)' | ||
| ); | ||
| }); | ||
|
|
||
| it('should throw when the prototype is not an object', function() { | ||
| expect(function() { | ||
| create(1); | ||
| }).toThrow( | ||
| 'Object prototype may only be an Object' | ||
| ); | ||
| }); | ||
|
|
||
| it('should throw when properties are given', function() { | ||
| expect(function() { | ||
| create({}, {}); | ||
| }).toThrow( | ||
| 'This create() implementation does not support assigning properties' | ||
| ); | ||
| }); | ||
|
|
||
| it('should create an object that inherits from prototype', function() { | ||
| var proto = {}; | ||
| var object = create(proto); | ||
|
|
||
| proto.foo = 'bar'; | ||
| expect(object.foo).toBe('bar'); | ||
| }); | ||
|
|
||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** | ||
| * Copyright 2013-2015, Facebook, Inc. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. An additional grant | ||
| * of patent rights can be found in the PATENTS file in the same directory. | ||
| * | ||
| * @emails react-core | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| require('mock-modules') | ||
| .dontMock('Object.freeze'); | ||
|
|
||
| var freeze; | ||
|
|
||
| var runnerCanFreeze = false; | ||
| try { | ||
| var obj = {foo: 'bar'}; | ||
| Object.freeze(obj); | ||
| try { | ||
| obj.foo = 'baz'; | ||
| runnerCanFreeze = obj.foo === 'bar'; | ||
| } catch (e) { | ||
| if (e instanceof TypeError) { | ||
| runnerCanFreeze = true; | ||
| } | ||
| } | ||
| } catch (x) {} | ||
|
|
||
| describe('Object.freeze', function() { | ||
|
|
||
| beforeEach(function() { | ||
| freeze = require('Object.freeze'); | ||
| }); | ||
|
|
||
| it('should not throw when the argument is an object', function() { | ||
| expect(function() { | ||
| freeze({}); | ||
| }).not.toThrow(); | ||
| }); | ||
|
|
||
| it('throws if the argument is not an object', function() { | ||
| expect(function() { | ||
| freeze(1); | ||
| }).toThrow( | ||
| 'freeze can only be called an Object' | ||
| ); | ||
| }); | ||
|
|
||
| it('should return the same object it is given', function() { | ||
| var obj = {}; | ||
|
|
||
| var returnValue = freeze(obj); | ||
|
|
||
| expect(returnValue).toBe(obj); | ||
| }); | ||
|
|
||
| it('should freeze the object if the native Object.freeze can', function() { | ||
| if ( !runnerCanFreeze ) { | ||
| pending(); | ||
| return; | ||
| } | ||
|
|
||
| var obj = {foo: 'bar'}; | ||
| freeze(obj); | ||
| try { | ||
| obj.foo = 'baz'; | ||
| } catch (x) {} | ||
|
|
||
| expect(obj.foo).toBe('bar'); | ||
| }) | ||
|
|
||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems superfluous to me at least.
Object.createshould be enough, a broken environment is not our problem I would think...