mirror of https://github.com/svaarala/duktape.git
Browse Source
* Implement Proxy.revocable() and add test case coverage for some Proxy revocation basics. * Fix revoked Proxy handling in instanceof and Array.isArray(), and add test coverage. * Fix revoked Proxy handling in call setup, and add test coverage. Chained Proxies still not supported in call handling. * Add stack top asserts for internal duk_prop_xxx.c file APIs: defown, delete, enum, get, getown, has, ownpropkeys, set. * Fix unused duk_hobject layouts from property table init code in src-tools.pull/2487/head
Sami Vaarala
2 years ago
25 changed files with 566 additions and 90 deletions
@ -0,0 +1,40 @@ |
|||
/*=== |
|||
[object Object] |
|||
true |
|||
[object Object] |
|||
true true true |
|||
[object Function] |
|||
true true true |
|||
undefined undefined undefined undefined |
|||
undefined undefined undefined undefined |
|||
===*/ |
|||
|
|||
var target = { foo: 123 }; |
|||
|
|||
var P = Proxy.revocable(target, {}); |
|||
print(Object.prototype.toString.call(P)); |
|||
print(Object.getPrototypeOf(P) === Object.prototype); |
|||
|
|||
print(Object.prototype.toString.call(P.proxy)); |
|||
var pd = Object.getOwnPropertyDescriptor(P, 'proxy'); |
|||
print(pd.writable, pd.enumerable, pd.writable); |
|||
|
|||
print(Object.prototype.toString.call(P.revoke)); |
|||
var pd = Object.getOwnPropertyDescriptor(P, 'revoke'); |
|||
print(pd.writable, pd.enumerable, pd.writable); |
|||
|
|||
Object.getOwnPropertyNames(P).forEach(function (k) { |
|||
if (k === 'proxy' || k === 'revoke') { |
|||
return; |
|||
} |
|||
print('extra key:', k); |
|||
}); |
|||
Object.getOwnPropertySymbols(P).forEach(function (s) { |
|||
print('extra symbol:', String(s)); |
|||
}); |
|||
|
|||
var pd = Object.getOwnPropertyDescriptor(P.revoke, 'name') || {}; |
|||
print(pd.value, pd.writable, pd.enumerable, pd.writable); |
|||
|
|||
var pd = Object.getOwnPropertyDescriptor(P.revoke, 'length') || {}; |
|||
print(pd.value, pd.writable, pd.enumerable, pd.writable); |
@ -0,0 +1,49 @@ |
|||
/*=== |
|||
call |
|||
NaN |
|||
revoke |
|||
revoked |
|||
call |
|||
TypeError |
|||
revoke again |
|||
revoked |
|||
call |
|||
TypeError |
|||
done |
|||
===*/ |
|||
|
|||
var P = Proxy.revocable(Math.cos, {}); |
|||
var F = P.proxy; |
|||
|
|||
try { |
|||
print('call'); |
|||
print(F()); |
|||
} catch (e) { |
|||
print(e.name); |
|||
} |
|||
|
|||
print('revoke'); |
|||
P.revoke(); |
|||
print('revoked'); |
|||
|
|||
try { |
|||
print('call'); |
|||
print(F()); |
|||
} catch (e) { |
|||
print(e.name); |
|||
//print(e.stack);
|
|||
} |
|||
|
|||
print('revoke again'); // nop
|
|||
P.revoke(); |
|||
print('revoked'); |
|||
|
|||
try { |
|||
print('call'); |
|||
print(F()); |
|||
} catch (e) { |
|||
print(e.name); |
|||
//print(e.stack);
|
|||
} |
|||
|
|||
print('done'); |
@ -0,0 +1,23 @@ |
|||
/*=== |
|||
false |
|||
undefined |
|||
TypeError |
|||
done |
|||
===*/ |
|||
|
|||
var target = function test() {}; |
|||
var P = Proxy.revocable(target, {}); |
|||
try { |
|||
print({} instanceof P.proxy); |
|||
} catch (e) { |
|||
print(e.name); |
|||
//print(e.stack);
|
|||
} |
|||
print(P.revoke()); |
|||
try { |
|||
print({} instanceof P.proxy); |
|||
} catch (e) { |
|||
print(e.name); |
|||
//print(e.stack);
|
|||
} |
|||
print('done'); |
@ -0,0 +1,23 @@ |
|||
/*=== |
|||
true |
|||
undefined |
|||
TypeError |
|||
done |
|||
===*/ |
|||
|
|||
var target = []; |
|||
var P = Proxy.revocable(target, {}); |
|||
try { |
|||
print(Array.isArray(P.proxy)); |
|||
} catch (e) { |
|||
print(e.name); |
|||
//print(e.stack);
|
|||
} |
|||
print(P.revoke()); |
|||
try { |
|||
print(Array.isArray(P.proxy)); |
|||
} catch (e) { |
|||
print(e.name); |
|||
//print(e.stack);
|
|||
} |
|||
print('done'); |
Loading…
Reference in new issue