Revision: 5427
Author: [email protected]
Date: Wed May 29 10:27:13 2013
Log: Clean up tame() and untame().
https://codereview.appspot.com/9857043
* Don't has() the WeakMap, just get() and check the result, which cannot
be falsy since WeakMaps contain no primitives. Hopefully faster.
* Remove redundant primitive-value test; r5149 / issue 1571 introduced a
fully general test without removing the existing one.
[email protected]
http://code.google.com/p/google-caja/source/detail?r=5427
Modified:
/trunk/src/com/google/caja/plugin/taming-membrane.js
=======================================
--- /trunk/src/com/google/caja/plugin/taming-membrane.js Thu Apr 11
12:41:50 2013
+++ /trunk/src/com/google/caja/plugin/taming-membrane.js Wed May 29
10:27:13 2013
@@ -254,23 +254,20 @@
*/
function tame(f) {
if (f !== Object(f)) {
- // Language primitive
+ // Primitive value; tames to self
return f;
}
var ftype = typeof f;
- if (ftype !== 'function' && ftype !== 'object') {
- // Primitive value; tames to self
- return f;
- } else if (Array.isArray(f)) {
+ if (Array.isArray(f)) {
// No tamesTo(...) for arrays; we copy across the membrane
return tameArray(f);
}
- if (tameByFeral.has(f)) { return tameByFeral.get(f); }
+ var t = tameByFeral.get(f);
+ if (t) { return t; }
if (feralByTame.has(f)) {
throw new TypeError('Tame object found on feral side of taming
membrane: '
+ f + '. The membrane has previously been compromised.');
}
- var t = void 0;
if (ftype === 'object') {
var ctor = privilegedAccess.directConstructor(f);
if (ctor === void 0) {
@@ -554,18 +551,16 @@
*/
function untame(t) {
if (t !== Object(t)) {
- // language primitive
+ // Primitive value; untames to self
return t;
}
var ttype = typeof t;
- if (ttype !== 'function' && ttype !== 'object') {
- // Primitive value; untames to self
- return t;
- } else if (Array.isArray(t)) {
+ if (Array.isArray(t)) {
// No tamesTo(...) for arrays; we copy across the membrane
return untameArray(t);
}
- if (feralByTame.has(t)) { return feralByTame.get(t); }
+ var f = feralByTame.get(t);
+ if (f) { return f; }
if (tameByFeral.has(t)) {
throw new TypeError('Feral object found on tame side of taming
membrane: '
+ t + '. The membrane has previously been compromised.');
@@ -573,7 +568,6 @@
if (!privilegedAccess.isDefinedInCajaFrame(t)) {
throw new TypeError('Host object leaked without being tamed');
}
- var f = void 0;
if (ttype === 'object') {
var ctor = privilegedAccess.directConstructor(t);
if (ctor === privilegedAccess.BASE_OBJECT_CONSTRUCTOR) {
--
---
You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.