Reviewers: felix8a,
Description:
On es5/3 on Safari 5, array-likes were implemented with platform
getters, but these properties were to be overridden with platform
assignment, which doesn't work for inherited accessor properties with
no setters. This adds a platform setter to such properties, allowing
override by platform assignment.
Please review this at https://codereview.appspot.com/12767049/
Affected files:
M src/com/google/caja/es53.js
Index: src/com/google/caja/es53.js
===================================================================
--- src/com/google/caja/es53.js (revision 5561)
+++ src/com/google/caja/es53.js (working copy)
@@ -50,6 +50,39 @@
var gopd = Object.getOwnPropertyDescriptor;
var defProp = Object.defineProperty;
+ /**
+ * Some of the array-like definitions below use platform
+ * getters. However, the intent is not to disallow override by
+ * platform assignment on objects that inherit from the
+ * array-like. See <a href=
+ * "https://code.google.com/p/google-caja/issues/detail?id=1842"
+ * >Safari 5 es5/3 using platform accessors in array-likes
+ * badly</a>.
+ */
+ function defOverridableProp(obj, name, desc) {
+ function setter(newValue) {
+ if (obj === this) {
+ throw new TypeError('property "' + name +
+ '" not defined to be settable');
+ }
+ if (!!gopd(this, name)) {
+ this[name] = newValue;
+ }
+ // TODO(erights): Do all the inherited property checks
+ defProp(this, name, {
+ value: newValue,
+ writable: true,
+ enumerable: true,
+ configurable: true
+ });
+ }
+ if (('get' in desc) && !('set' in desc)) {
+ desc.set = setter; // TODO(erights): Should make a derived copy
+ }
+ return defProp(obj, name, desc);
+ }
+
+
// Given an object defined in an es53 frame, we can tell which
// Object.prototype it inherits from.
Object.prototype.baseProto___ = Object.prototype;
@@ -4322,7 +4355,7 @@
var numericGetters = (function () {
var obj = {};
try {
- defProp(obj, 0, {
+ defOverridableProp(obj, 0, {
get: function () { return obj; }
});
if (obj[0] !== obj) { return false; }
@@ -4497,7 +4530,7 @@
// Install native numeric getters.
for (var i = 0; i < len; i++) {
(function(j) {
- defProp(BAL.prototype, j, {
+ defOverridableProp(BAL.prototype, j, {
get: markConstFunc(function() {
var itemGetter = itemMap.get(this);
return itemGetter ? itemGetter.i___(j) : void 0;
@@ -4507,7 +4540,7 @@
})(i);
}
// Install native length getter.
- defProp(BAL.prototype, 'length', { get: lengthGetter });
+ defOverridableProp(BAL.prototype, 'length', { get: lengthGetter
});
// Whitelist prototype and prototype.constructor for ES5/3.
BAL.DefineOwnProperty___('prototype', { value: BAL.prototype });
BAL.prototype.DefineOwnProperty___('constructor', { value: BAL
});
--
---
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.