Add methods to public API to determine the mode in use (es5-only version). (issue 236800043 by kpreid@google.com)

2 views
Skip to first unread message

re...@codereview-hr.appspotmail.com

unread,
Apr 28, 2015, 5:44:23 PM4/28/15
to eri...@gmail.com, kpr...@google.com, google-ca...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reviewers: MarkM,

Description:
This is currently useful for migrating off ES5/3 while still using
already-cajoled content when possible.

It has been designed to be future-proof in case of the introduction
of a new or variant implementation strategy, by offering independent
answers to "is this ES5/3" and "is this SES" rather than an
enumeration (or boolean), which could not express e.g. "this is not
actually SES, but if you haven't heard of it you should treat it like
SES".

Please review this at https://codereview.appspot.com/236800043/

Affected files (+22, -0 lines):
M src/com/google/caja/plugin/caja.js
M src/com/google/caja/plugin/ses-frame-group.js
M tests/com/google/caja/plugin/test-cajajs-invocation.js


Index: src/com/google/caja/plugin/caja.js
diff --git a/src/com/google/caja/plugin/caja.js
b/src/com/google/caja/plugin/caja.js
index
2bbb39ddfab40ba53716e0d45faae79dab669f73..34eaa35358e9fe9d4d1d62898d905ca08801f6c6
100644
--- a/src/com/google/caja/plugin/caja.js
+++ b/src/com/google/caja/plugin/caja.js
@@ -143,6 +143,10 @@ var caja = (function () {
'makeDefensibleObject___': premature,
'makeDefensibleFunction___': premature,

+ // Introspection
+ 'isES53': premature,
+ 'isSES': premature,
+
// Esoteric functions
'initFeralFrame': initFeralFrame,
'makeFrameGroup': makeFrameGroup,
Index: src/com/google/caja/plugin/ses-frame-group.js
diff --git a/src/com/google/caja/plugin/ses-frame-group.js
b/src/com/google/caja/plugin/ses-frame-group.js
index
dc2a57a9488ff7aed05b3c132f0d3a1a1b930c77..44ce144bd1fbac6301ea0ba66b9beb176a38d43f
100644
--- a/src/com/google/caja/plugin/ses-frame-group.js
+++ b/src/com/google/caja/plugin/ses-frame-group.js
@@ -101,6 +101,13 @@ function SESFrameGroup(cajaInt, config, tamingWin,
feralWin,
USELESS: USELESS,
iframe: window.frameElement,

+ // For clients which need to know details/quirks.
+ // These are functions so that the caja.js "premature" mechanism works.
+ // These are individual questions so that it can be expanded to cover
+ // unforeseen future cases ("almost like", "none of the above").
+ isES53: function() { return false; },
+ isSES: function() { return true; },
+
Q: Q,

makeES5Frame: makeES5Frame,
Index: tests/com/google/caja/plugin/test-cajajs-invocation.js
diff --git a/tests/com/google/caja/plugin/test-cajajs-invocation.js
b/tests/com/google/caja/plugin/test-cajajs-invocation.js
index
106a13823eb99cf711f21a749226011185463612..9114f0962814300a9095cecd3b65f704f532cc36
100644
--- a/tests/com/google/caja/plugin/test-cajajs-invocation.js
+++ b/tests/com/google/caja/plugin/test-cajajs-invocation.js
@@ -558,6 +558,17 @@
}, 0);
});

+ jsunitRegister('testImplQuestions', function testImplQuestions() {
+ // Wait for default frame group because we're using it via caja.*.
+ caja.whenReady(function testImplQuestions_inner() {
+ assertEquals('isES53', false, frameGroup.isES53());
+ assertEquals('isES53', false, caja.isES53());
+ assertEquals('isSES', true, frameGroup.isSES());
+ assertEquals('isSES', true, caja.isSES());
+ jsunitPass('testImplQuestions');
+ });
+ });
+
readyToTest();
jsunitRun();
});


eri...@gmail.com

unread,
Apr 28, 2015, 5:47:16 PM4/28/15
to kpr...@google.com, google-ca...@googlegroups.com, re...@codereview-hr.appspotmail.com
Reply all
Reply to author
Forward
0 new messages