Reviewers: felix8a,
Description:
* isNativeFunction self-test assumed Function.prototype's toString was
not "[native code]", which it is on Safari. (From r5574.)
* Removed accidental duplicate of isNativeFunction produced when scanner
was split into two files. (From r5576.)
Please review this at https://codereview.appspot.com/13602044/
Affected files (+3, -31 lines):
M tests/com/google/caja/plugin/test-scan-core.js
M tests/com/google/caja/plugin/test-scan-guest.js
Index: tests/com/google/caja/plugin/test-scan-guest.js
===================================================================
--- tests/com/google/caja/plugin/test-scan-guest.js (revision 5591)
+++ tests/com/google/caja/plugin/test-scan-guest.js (working copy)
@@ -43,31 +43,6 @@
var PLAIN_CALL = scanning.PLAIN_CALL;
var getFunctionName = scanning.getFunctionName;
- function isNativeFunction(f) {
- try {
- return (/^[^{}]*\{\s*\[native code\]\s*}\s*$/
- .test(Function.prototype.toString.call(f)));
- } catch (e) {
- // ES5/3 Function.prototype is semi-toxic and throws in this case.
- //
- // Also, Function.prototype is not a native function in the sense we
care
- // about (it is exercised separately), and since it doesn't match the
- // above pattern (its body is empty), returning false is consistent
with
- // the SES case.
- return false;
- }
- }
- // self-test
- if (isNativeFunction(Function.prototype)) {
- throw new Error('isNativeFunction: failed on Function.prototype');
- }
- if (!isNativeFunction(Math.sin)) { // arbitrary boring native function
- throw new Error('isNativeFunction: failed on Math.sin');
- }
- if (isNativeFunction(function() {})) {
- throw new Error('isNativeFunction: failed on non-native');
- }
-
/** Fake evaluator for ES5/3 compatibility */
function simpleEval(env, expr) {
var match;
Index: tests/com/google/caja/plugin/test-scan-core.js
===================================================================
--- tests/com/google/caja/plugin/test-scan-core.js (revision 5591)
+++ tests/com/google/caja/plugin/test-scan-core.js (working copy)
@@ -52,16 +52,13 @@
// ES5/3 Function.prototype is semi-toxic and throws in this case.
//
// Also, Function.prototype is not a native function in the sense we
care
- // about (it is exercised separately), and since it doesn't match the
- // above pattern (its body is empty), returning false is consistent
with
- // the SES case.
+ // about (it is exercised separately), and also does not throw, so we
+ // don't care about the return value.
return false;
}
}
// self-test
- if (isNativeFunction(Function.prototype)) {
- throw new Error('isNativeFunction: failed on Function.prototype');
- }
+ isNativeFunction(Function.prototype); // don't care, must not throw
if (!isNativeFunction(Math.sin)) { // arbitrary boring native function
throw new Error('isNativeFunction: failed on Math.sin');
}
--
---
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.