Revision: 4233
Author: [email protected]
Date: Mon Aug 9 10:03:14 2010
Log: [?1034hAdd support for cellpadding and cellspacing
http://codereview.appspot.com/1903053
http://code.google.com/p/google-caja/issues/detail?id=1233
This covers a number of table attributes but does not tackle
script::type mentioned in that issue.
[email protected]
http://code.google.com/p/google-caja/source/detail?r=4233
Modified:
/trunk/src/com/google/caja/plugin/domita.js
/trunk/tests/com/google/caja/plugin/domita_test_untrusted.html
=======================================
--- /trunk/src/com/google/caja/plugin/domita.js Fri Aug 6 22:04:29 2010
+++ /trunk/src/com/google/caja/plugin/domita.js Mon Aug 9 10:03:14 2010
@@ -137,11 +137,24 @@
throw new Error('Expected function not ' + typeof aCallback);
}
}
+
+ function defAttributeAlias(ctor, name, toValue, fromValue) {
+ var getterSetterSuffix = String.fromCharCode(name.charCodeAt(0) & ~32)
+ + name.substring(1);
+ ctor.prototype['get' + getterSetterSuffix] = function () {
+ return toValue(this.getAttribute(name));
+ };
+ ctor.prototype['set' + getterSetterSuffix] = function (value) {
+ this.setAttribute(name, fromValue(value));
+ return value;
+ };
+ }
return {
exportFields: exportFields,
ensureValidCallback: ensureValidCallback,
- applyAccessors: applyAccessors
+ applyAccessors: applyAccessors,
+ defAttributeAlias: defAttributeAlias
};
};
@@ -3013,7 +3026,9 @@
function TameTableElement(node, editable) {
TameTableCompElement.call(this, node, editable);
- classUtils.exportFields(this, ['tBodies', 'tHead', 'tFoot']);
+ classUtils.exportFields(
+ this,
+
['tBodies', 'tHead', 'tFoot', 'cellPadding', 'cellSpacing', 'border']);
}
inertCtor(TameTableElement, TameTableCompElement, 'HTMLTableElement');
TameTableElement.prototype.getTBodies = function () {
@@ -3060,6 +3075,13 @@
requireIntIn(index, -1, this.node___.rows.length);
this.node___.deleteRow(index);
};
+ function fromInt(x) { return '' + (x | 0); } // coerce null and false
to 0
+ classUtils.defAttributeAlias(
+ TameTableElement, 'cellPadding', Number, fromInt);
+ classUtils.defAttributeAlias(
+ TameTableElement, 'cellSpacing', Number, fromInt);
+ classUtils.defAttributeAlias(
+ TameTableElement, 'border', Number, fromInt);
___.all2(___.grantTypedMethod, TameTableElement.prototype,
['createTHead', 'deleteTHead', 'createTFoot', 'deleteTFoot',
=======================================
--- /trunk/tests/com/google/caja/plugin/domita_test_untrusted.html Fri Aug
6 22:04:29 2010
+++ /trunk/tests/com/google/caja/plugin/domita_test_untrusted.html Mon Aug
9 10:03:14 2010
@@ -419,7 +419,7 @@
</p>
<div class="testcontainer" id="test-table-elements">
- <table>
+ <table id='test-table-elements-table'>
<thead>
<tr>
<td>h00</td>
@@ -3102,6 +3102,9 @@
var tr_b1 = document.getElementById('test-table-elements-tr-b1');
assertEquals(1, tr_b1.sectionRowIndex);
assertEquals(2, tr_b1.rowIndex);
+ var table = document.getElementById('test-table-elements-table');
+ assertEquals(0, table.cellPadding);
+ assertEquals(0, table.cellSpacing);
pass('test-table-elements');
});