Reviewers: MarkM,
Description:
* Whitelist %TypedArray%.from and %TypedArray%.of (or the same methods
on the individual array constructors, as currently implemented in
Chrome).
* Add scan coverage for those methods.
Unrelated but needed to be done:
* Add missing always-throws declaration for generator throw method.
Please review this at https://codereview.appspot.com/253440043/
Affected files (+34, -2 lines):
M src/com/google/caja/ses/whitelist.js
M tests/com/google/caja/plugin/test-scan-guest.js
Index: src/com/google/caja/ses/whitelist.js
diff --git a/src/com/google/caja/ses/whitelist.js
b/src/com/google/caja/ses/whitelist.js
index
f2c415aaca9def6c918cf18077a70c154f7b3d81..6f07570a39333eb25cd435f962372657644ddb8c
100644
--- a/src/com/google/caja/ses/whitelist.js
+++ b/src/com/google/caja/ses/whitelist.js
@@ -163,6 +163,8 @@ var ses;
length: '*', // does not inherit from Function.prototype on
Chrome
name: '*', // ditto
BYTES_PER_ELEMENT: '*',
+ from: t,
+ of: t,
prototype: {
buffer: 'maybeAccessor',
byteOffset: 'maybeAccessor',
Index: tests/com/google/caja/plugin/test-scan-guest.js
diff --git a/tests/com/google/caja/plugin/test-scan-guest.js
b/tests/com/google/caja/plugin/test-scan-guest.js
index
7d1bd1e7c73e37c3ae9d130f06b933c55819157e..a28eb2e237e3cc2a254289142ecd4b88f7a90f33
100644
--- a/tests/com/google/caja/plugin/test-scan-guest.js
+++ b/tests/com/google/caja/plugin/test-scan-guest.js
@@ -594,6 +594,8 @@
// fresh because it returns { value: ..., done: ... }
freshResult(G.any(
genMethod(G.value('foo')), genMethod())));
+ expectedAlwaysThrow.set(
+ Ref.is(generatorIteratorPrototype['throw']), true);
}
argsByIdentity(cajaVM.anonIntrinsics.ThrowTypeError, genAllCall());
@@ -1348,12 +1350,18 @@
genNumbers(2))));
function setupTypedArray(name, doAllCalls) {
var ref = RefAnyFrame(name);
- var ctor = window[name];
+ var ctor = evalInEnv(window, name);
functionArgs.set(ref, freshResult(doAllCalls
? typedArrayCall
: genAllCall(G.value(0))));
- obtainInstance.define(ctor, new ctor(3));
+ if (name === 'cajaVM.anonIntrinsics.TypedArray') {
+ if (ctor) { // some browsers don't implement it yet
+ obtainInstance.define(ctor, new Int8Array(3));
+ }
+ } else {
+ obtainInstance.define(ctor, new ctor(3));
+ }
argsByAnyFrame(name + '.prototype.set', doAllCalls
? G.any(
@@ -1364,10 +1372,32 @@
doAllCalls
? genMethod(genSmallInteger, genSmallInteger)
: genMethod(G.value(1), G.value(2))));
+
+ function genTACtorMethod() {
+ // .from and .of are on %TypedArray% but need to be called with
+ // this = a subclass ctor.
+ var thisArg = ctor === cajaVM.anonIntrinsics.TypedArray
+ ? Int8Array : ctor;
+ return G.tuple(G.value(thisArg), G.tuple.apply(undefined,
arguments));
+ }
+
+ argsByAnyFrame(name + '.from', freshResult(
+ doAllCalls
+ ? genTACtorMethod(genArray, G.value(dummyFunction, null))
+ : genTACtorMethod(G.value([]), G.value(dummyFunction))));
+
+ argsByAnyFrame(name + '.of', freshResult(
+ doAllCalls
+ ? genTACtorMethod(genJSONValue)
+ : genTACtorMethod(G.value(1))));
}
// To save on scan time, we only fully exercise some of the array
types
// (chosen for coverage of different cases: 1-byte, clamped,
endianness,
// floats).
+ // TODO(kpreid): Once all implementations are conformant with ES
2015,
+ // we only need to look at the intrinsic for most things, not each
+ // subtype.
+ setupTypedArray('cajaVM.anonIntrinsics.TypedArray', true);
setupTypedArray('Int8Array', true);
setupTypedArray('Uint8Array', false);
setupTypedArray('Uint8ClampedArray', true);
--
---
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/d/optout.