Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make array and object prototype singletons immutable for now (#4142)
* Make array and object prototype singletons immutable for now * Improve coverage * Fix incorrect spread element handling
- Loading branch information
1 parent
c4f9d13
commit aa1b227
Showing
20 changed files
with
131 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
3 changes: 3 additions & 0 deletions
3
test/form/samples/object-expression/reassign-prop-without-proto/_config.js
This file contains 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,3 @@ | ||
module.exports = { | ||
description: 'correctly deoptimizes when there is no proto' | ||
}; |
7 changes: 7 additions & 0 deletions
7
test/form/samples/object-expression/reassign-prop-without-proto/_expected.js
This file contains 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,7 @@ | ||
const obj = { __proto__: null }; | ||
|
||
obj.flag = true; | ||
|
||
if (obj.flag) { | ||
console.log('mutated'); | ||
} |
7 changes: 7 additions & 0 deletions
7
test/form/samples/object-expression/reassign-prop-without-proto/main.js
This file contains 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,7 @@ | ||
const obj = { __proto__: null }; | ||
|
||
obj.flag = true; | ||
|
||
if (obj.flag) { | ||
console.log('mutated'); | ||
} |
4 changes: 4 additions & 0 deletions
4
test/form/samples/object-expression/unknown-getter-no-side-effect/_config.js
This file contains 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,4 @@ | ||
module.exports = { | ||
description: 'removes unknown getter access without side effect', | ||
options: { external: ['external'] } | ||
}; |
1 change: 1 addition & 0 deletions
1
test/form/samples/object-expression/unknown-getter-no-side-effect/_expected.js
This file contains 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 @@ | ||
import 'external'; |
7 changes: 7 additions & 0 deletions
7
test/form/samples/object-expression/unknown-getter-no-side-effect/main.js
This file contains 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,7 @@ | ||
import { unknown } from 'external'; | ||
|
||
const obj = { | ||
get [unknown]() {} | ||
}; | ||
|
||
obj.prop; |
4 changes: 4 additions & 0 deletions
4
test/form/samples/object-expression/unknown-setter-no-side-effect/_config.js
This file contains 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,4 @@ | ||
module.exports = { | ||
description: 'removes unknown setter access without side effect', | ||
options: { external: ['external'] } | ||
}; |
1 change: 1 addition & 0 deletions
1
test/form/samples/object-expression/unknown-setter-no-side-effect/_expected.js
This file contains 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 @@ | ||
import 'external'; |
7 changes: 7 additions & 0 deletions
7
test/form/samples/object-expression/unknown-setter-no-side-effect/main.js
This file contains 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,7 @@ | ||
import { unknown } from 'external'; | ||
|
||
const obj = { | ||
set [unknown](value) {} | ||
}; | ||
|
||
obj.prop = true; |
This file contains 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,3 @@ | ||
module.exports = { | ||
description: 'correctly deoptimizes when there is no proto' | ||
}; |
This file contains 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,19 @@ | ||
const a = [false, , true]; | ||
const b = [false, , true, ...a, false, , true, ...a]; | ||
|
||
let count = 0; | ||
|
||
b[0] ? count+= 10: count++; | ||
b[1] ? count+= 10: count++; | ||
b[2] ? count+= 10: count++; | ||
b[3] ? count+= 10: count++; | ||
b[4] ? count+= 10: count++; | ||
b[5] ? count+= 10: count++; | ||
b[6] ? count+= 10: count++; | ||
b[7] ? count+= 10: count++; | ||
b[8] ? count+= 10: count++; | ||
b[9] ? count+= 10: count++; | ||
b[10] ? count+= 10: count++; | ||
b[11] ? count+= 10: count++; | ||
|
||
assert.strictEqual(count, 48); |
2 changes: 1 addition & 1 deletion
2
test/function/samples/modify-this-via-getter/unknown-prop-getter/_config.js
This file contains 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
19 changes: 19 additions & 0 deletions
19
test/function/samples/object-deep-access-effect/_config.js
This file contains 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,19 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'throws when an nested property of an unknown object property is accessed', | ||
context: { | ||
require() { | ||
return { unknown: 'prop' }; | ||
} | ||
}, | ||
options: { | ||
external: ['external'] | ||
}, | ||
exports({ expectError }) { | ||
assert.throws(expectError, { | ||
name: 'TypeError', | ||
message: "Cannot read property 'prop' of undefined" | ||
}); | ||
} | ||
}; |
This file contains 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,6 @@ | ||
import { unknown } from 'external'; | ||
|
||
export function expectError() { | ||
const obj = {}; | ||
obj[unknown].prop; | ||
} |
This file contains 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,3 @@ | ||
module.exports = { | ||
description: 'tracks array mutations' | ||
}; |
This file contains 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,13 @@ | ||
let push = false; | ||
|
||
const getArray = () => { | ||
const array = []; | ||
if (push) { | ||
array.push(true); | ||
} | ||
return array; | ||
}; | ||
|
||
assert.strictEqual(getArray()[0] || false, false); | ||
push = true; | ||
assert.strictEqual(getArray()[0] || false, true); |