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.
105 lines
1.6 KiB
105 lines
1.6 KiB
/*===
|
|
extensible: true
|
|
extensible: false
|
|
extensible: false
|
|
undefined
|
|
bar
|
|
===*/
|
|
|
|
function basicTest() {
|
|
function printObj(o) {
|
|
print('extensible: ' + Object.isExtensible(o));
|
|
}
|
|
|
|
var proto = {};
|
|
var obj = Object.create(proto);
|
|
|
|
printObj(obj);
|
|
Object.preventExtensions(obj);
|
|
printObj(obj);
|
|
Object.preventExtensions(obj);
|
|
printObj(obj);
|
|
|
|
try {
|
|
obj.foo = 'bar';
|
|
} catch (e) {
|
|
print(e.name);
|
|
}
|
|
|
|
print(obj.foo);
|
|
|
|
// ancestor can still be extended
|
|
|
|
try {
|
|
proto.foo = 'bar';
|
|
} catch (e) {
|
|
print(e.name);
|
|
}
|
|
|
|
print(obj.foo);
|
|
}
|
|
|
|
try {
|
|
basicTest();
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
|
|
/*===
|
|
isExtensible 0
|
|
TypeError
|
|
isExtensible 1
|
|
TypeError
|
|
isExtensible 2
|
|
TypeError
|
|
isExtensible 3
|
|
TypeError
|
|
isExtensible 4
|
|
TypeError
|
|
isExtensible 5
|
|
TypeError
|
|
isExtensible 6
|
|
isExtensible 7
|
|
preventExtensions 0
|
|
TypeError
|
|
preventExtensions 1
|
|
TypeError
|
|
preventExtensions 2
|
|
TypeError
|
|
preventExtensions 3
|
|
TypeError
|
|
preventExtensions 4
|
|
TypeError
|
|
preventExtensions 5
|
|
TypeError
|
|
preventExtensions 6
|
|
preventExtensions 7
|
|
===*/
|
|
|
|
function coercionTest() {
|
|
var values = [ undefined, null, true, false, 123, 'foo', [1,2,3], { foo: 1, bar: 1 } ];
|
|
|
|
for (i = 0; i < values.length; i++) {
|
|
print('isExtensible', i);
|
|
try {
|
|
Object.isExtensible(values[i]);
|
|
} catch (e) {
|
|
print(e.name);
|
|
}
|
|
}
|
|
|
|
for (i = 0; i < values.length; i++) {
|
|
print('preventExtensions', i);
|
|
try {
|
|
Object.preventExtensions(values[i]);
|
|
} catch (e) {
|
|
print(e.name);
|
|
}
|
|
}
|
|
}
|
|
|
|
try {
|
|
coercionTest();
|
|
} catch (e) {
|
|
print(e);
|
|
}
|
|
|