mirror of https://github.com/svaarala/duktape.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.5 KiB
54 lines
1.5 KiB
11 years ago
|
/*
|
||
|
* If the Array.prototype contains numeric elements which are write protected
|
||
|
* (but configurable), it should be possible to create an array literal with
|
||
|
* an overriding value. A normal property assignment would fail because the
|
||
11 years ago
|
* inherited property is not writable. An array initializer is supposed to
|
||
|
* use [[DefineOwnProperty]] which allows an own property to be created even
|
||
|
* if there is an inherited property which would normally prevent a write.
|
||
11 years ago
|
*/
|
||
|
|
||
|
/*===
|
||
|
defineProperty success
|
||
|
0 inherit undefined
|
||
|
2 foo bar
|
||
|
0 inherit undefined
|
||
|
2 shouldsucceed bar
|
||
|
===*/
|
||
|
|
||
|
function test() {
|
||
|
var arr;
|
||
|
|
||
|
Object.defineProperty(Array.prototype,
|
||
|
'0',
|
||
|
{
|
||
|
value: 'inherit',
|
||
|
writable: false,
|
||
|
enumerable: true,
|
||
10 years ago
|
configurable: true
|
||
11 years ago
|
});
|
||
|
print('defineProperty success');
|
||
|
|
||
|
// No problem here: '0' not accessed
|
||
|
arr = [];
|
||
|
print(arr.length, arr[0], arr[1]);
|
||
|
|
||
|
// Again should succeed
|
||
|
var arr = ['foo', 'bar'];
|
||
|
print(arr.length, arr[0], arr[1]);
|
||
|
|
||
|
// Assignment should not work unless an own property already exists
|
||
|
arr = [];
|
||
|
arr[0] = 'shouldfail'; // failure is silent
|
||
|
print(arr.length, arr[0], arr[1]);
|
||
|
|
||
|
arr = ['foo', 'bar'];
|
||
|
arr[0] = 'shouldsucceed';
|
||
|
print(arr.length, arr[0], arr[1]);
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
test();
|
||
|
} catch (e) {
|
||
|
print(e);
|
||
|
}
|