LEFT | RIGHT |
1 // Copyright (C) 2013 Google Inc. | 1 // Copyright (C) 2013 Google Inc. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 if (object === Object(object)) { // not a primitive | 371 if (object === Object(object)) { // not a primitive |
372 expectedUnfrozen.setByIdentity(object, true); | 372 expectedUnfrozen.setByIdentity(object, true); |
373 } | 373 } |
374 }); | 374 }); |
375 } | 375 } |
376 | 376 |
377 var elementSpecimen = document.createElement('an-element-for-tests'); | 377 var elementSpecimen = document.createElement('an-element-for-tests'); |
378 var genFreshElement = G.apply(function() { | 378 var genFreshElement = G.apply(function() { |
379 return document.createElement('fresh-element'); | 379 return document.createElement('fresh-element'); |
380 }); | 380 }); |
381 | 381 |
382 var ArrayLike = cajaVM.makeArrayLike(largestSmallInteger); | 382 var ArrayLike = cajaVM.makeArrayLike(largestSmallInteger); |
383 | 383 |
384 function isArrayLikeCtor(o) { | 384 function isArrayLikeCtor(o) { |
385 // matching code text is a kludge to be able to recognize usurped | 385 // matching code text is a kludge to be able to recognize usurped |
386 // smaller ArrayLikes. | 386 // smaller ArrayLikes. |
387 return o === ArrayLike || /proto instanceof BAL/.test(o.toString()); | 387 return o === ArrayLike || /proto instanceof BAL/.test(o.toString()); |
388 } | 388 } |
389 | 389 |
390 var tamingEnv = directAccess.evalInTamingFrame('cajaVM.sharedImports'); | 390 var tamingEnv = directAccess.evalInTamingFrame('cajaVM.sharedImports'); |
391 function forEachFrame(code, callback) { | 391 function forEachFrame(code, callback) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 })); | 531 })); |
532 argsByProp('valueOf', genNoArgMethod); | 532 argsByProp('valueOf', genNoArgMethod); |
533 argsByProp('hasOwnProperty', genMethod(genString)); | 533 argsByProp('hasOwnProperty', genMethod(genString)); |
534 argsByProp('isPrototypeOf', genMethod(genObject)); // TODO abuse more | 534 argsByProp('isPrototypeOf', genMethod(genObject)); // TODO abuse more |
535 argsByProp('propertyIsEnumerable', genMethod(genString)); // TODO abuse | 535 argsByProp('propertyIsEnumerable', genMethod(genString)); // TODO abuse |
536 | 536 |
537 argsByProp('toLocaleString', genNoArgMethod); | 537 argsByProp('toLocaleString', genNoArgMethod); |
538 | 538 |
539 functionArgs.set(RefAnyFrame('Function'), G.none); | 539 functionArgs.set(RefAnyFrame('Function'), G.none); |
540 // TODO deal with function return val | 540 // TODO deal with function return val |
| 541 |
541 argsByAnyFrame('Function.prototype', genAllCall()); | 542 argsByAnyFrame('Function.prototype', genAllCall()); |
542 argsByIdentity(dummyFunction, genCall()); | 543 argsByIdentity(dummyFunction, genCall()); |
543 argsByAnyFrame('Function.prototype.apply', genMethod(genObject, genArray)); | 544 argsByAnyFrame('Function.prototype.apply', genMethod(genObject, genArray)); |
544 argsByAnyFrame('Function.prototype.bind', | 545 argsByAnyFrame('Function.prototype.bind', |
545 annotate(genMethod(genObject), function(context, thrown) { | 546 annotate(genMethod(genObject), function(context, thrown) { |
546 if (!thrown) { | 547 if (!thrown) { |
547 expectedUnfrozen.setByIdentity(context.get(), true); | 548 expectedUnfrozen.setByIdentity(context.get(), true); |
548 argsByIdentity(context.get(), G.value([refLeakCanary, []])); | 549 argsByIdentity(context.get(), G.value([refLeakCanary, []])); |
549 } | 550 } |
550 })); | 551 })); |
551 argsByAnyFrame('Function.prototype.call', genMethod(genObject, genObject)); | 552 argsByAnyFrame('Function.prototype.call', genMethod(genObject, genObject)); |
552 argsByAnyFrame('Function.prototype.toString', | 553 argsByAnyFrame('Function.prototype.toString', |
553 // TODO test invocation on Function.prototype itself | 554 // TODO test invocation on Function.prototype itself |
554 G.tuple(G.value(THIS), G.tuple())); | 555 G.tuple(G.value(THIS), G.tuple())); |
555 ···· | 556 |
556 argsByIdentity(cajaVM.intrinsics.ThrowTypeError, genAllCall()); | 557 // ES6 Generators |
557 expectedAlwaysThrow.setByIdentity(cajaVM.intrinsics.ThrowTypeError, true); | 558 if (cajaVM.anonIntrinsics.GeneratorFunction) { |
| 559 functionArgs.set(RefAnyFrame('cajaVM.anonIntrinsics.GeneratorFunction'), |
| 560 genAllCall); |
| 561 expectedAlwaysThrow.set( |
| 562 RefAnyFrame('cajaVM.anonIntrinsics.GeneratorFunction'), |
| 563 true); // SES disables constructor |
| 564 functionArgs.set( |
| 565 RefAnyFrame('cajaVM.anonIntrinsics.GeneratorFunction.prototype'), |
| 566 genAllCall); |
| 567 expectedAlwaysThrow.set( |
| 568 RefAnyFrame('cajaVM.anonIntrinsics.GeneratorFunction.prototype'), |
| 569 true); // the prototype of function*s is not callable |
| 570 |
| 571 // Using evalInTamingFrame because SES mitigated eval will reject |
| 572 // generator syntax when it parses. TODO(kpreid): use cajaVM.eval once we |
| 573 // fully support generators. |
| 574 var aGeneratorFunction = directAccess.evalInGuestFrame( |
| 575 '(function*() { "use strict"; ' +· |
| 576 'while (true) { try { yield 1; } catch (e) {} } })'); |
| 577 var aGenerator = aGeneratorFunction(); |
| 578 aGenerator.next(); // so .throw() will be caught |
| 579 obtainInstance.define(cajaVM.anonIntrinsics.GeneratorFunction, |
| 580 aGeneratorFunction); |
| 581 obtainInstance.define(cajaVM.anonIntrinsics.GeneratorFunction.prototype, |
| 582 aGenerator); |
| 583 ······ |
| 584 var generatorIteratorPrototype = |
| 585 cajaVM.anonIntrinsics.GeneratorFunction.prototype.prototype; |
| 586 ······ |
| 587 // TODO(kpreid): Would be nice to be able to say "these methods on any |
| 588 // subtype of Iterator". |
| 589 functionArgs.set( |
| 590 Ref.all( |
| 591 Ref.is(generatorIteratorPrototype.next), |
| 592 Ref.is(generatorIteratorPrototype['return']), |
| 593 Ref.is(generatorIteratorPrototype['throw'])), |
| 594 // fresh because it returns { value: ..., done: ... } |
| 595 freshResult(G.any( |
| 596 genMethod(G.value('foo')), genMethod()))); |
| 597 } |
| 598 |
| 599 argsByIdentity(cajaVM.anonIntrinsics.ThrowTypeError, genAllCall()); |
| 600 expectedAlwaysThrow.setByIdentity( |
| 601 cajaVM.anonIntrinsics.ThrowTypeError, true); |
558 // TODO test other intrinsics like %TypedArray% | 602 // TODO test other intrinsics like %TypedArray% |
559 | 603 |
560 argsByIdentity(Number, genAllCall(genSmallInteger)); | 604 argsByIdentity(Number, genAllCall(genSmallInteger)); |
561 argsByAnyFrame('Number.prototype.toExponential', | 605 argsByAnyFrame('Number.prototype.toExponential', |
562 genMethod(genSmallInteger)); | 606 genMethod(genSmallInteger)); |
563 argsByAnyFrame('Number.prototype.toFixed', genMethod(genSmallInteger)); | 607 argsByAnyFrame('Number.prototype.toFixed', genMethod(genSmallInteger)); |
564 argsByAnyFrame('Number.prototype.toPrecision', genMethod(genSmallInteger)); | 608 argsByAnyFrame('Number.prototype.toPrecision', genMethod(genSmallInteger)); |
565 | 609 |
566 function genArrayCall(argsGen) { | 610 function genArrayCall(argsGen) { |
567 return G.tuple( | 611 return G.tuple( |
568 G.any(genFreshArray, genArray, G.value(undefined, PLAIN_CALL)), | 612 G.any(genFreshArray, genArray, G.value(undefined, PLAIN_CALL)), |
569 argsGen); | 613 argsGen); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 expectedAlwaysThrow.setByIdentity(Array.prototype.sort, true); | 646 expectedAlwaysThrow.setByIdentity(Array.prototype.sort, true); |
603 argsByAnyFrame('Array.prototype.splice', freshResult( | 647 argsByAnyFrame('Array.prototype.splice', freshResult( |
604 genArrayCall(genNumbers(2)))); | 648 genArrayCall(genNumbers(2)))); |
605 argsByAnyFrame('Array.prototype.unshift', | 649 argsByAnyFrame('Array.prototype.unshift', |
606 genArrayCall(G.tuple(genJSONValue))); | 650 genArrayCall(G.tuple(genJSONValue))); |
607 | 651 |
608 argsByAnyFrame('Boolean', genAllCall(genBoolean)); | 652 argsByAnyFrame('Boolean', genAllCall(genBoolean)); |
609 | 653 |
610 argsByAnyFrame('String', genAllCall(genString)); | 654 argsByAnyFrame('String', genAllCall(genString)); |
611 argsByAnyFrame('String.fromCharCode', genMethod(genSmallInteger)); | 655 argsByAnyFrame('String.fromCharCode', genMethod(genSmallInteger)); |
612 ['big', 'blink', 'bold', 'fixed', 'italics', 'small', 'strong', 'strike', | 656 ['big', 'blink', 'bold', 'fixed', 'italics', 'small', 'strike', |
613 'sub', 'sup'].forEach(function(name) { | 657 'sub', 'sup'].forEach(function(name) { |
614 argsByAnyFrame('String.prototype.' + name, genNoArgMethod); | 658 argsByAnyFrame('String.prototype.' + name, genNoArgMethod); |
615 }); | 659 }); |
616 ['anchor', 'fontcolor', 'fontsize', 'link'].forEach(function(name) { | 660 ['anchor', 'fontcolor', 'fontsize', 'link'].forEach(function(name) { |
617 argsByAnyFrame('String.prototype.' + name, genMethod(genString)); | 661 argsByAnyFrame('String.prototype.' + name, genMethod(genString)); |
618 }); | 662 }); |
619 argsByAnyFrame('String.prototype.charAt', genMethod(genNumber)); | 663 argsByAnyFrame('String.prototype.charAt', genMethod(genNumber)); |
620 argsByAnyFrame('String.prototype.charCodeAt', genMethod(genNumber)); | 664 argsByAnyFrame('String.prototype.charCodeAt', genMethod(genNumber)); |
621 argsByAnyFrame('String.prototype.concat', genMethod(genString)); | 665 argsByAnyFrame('String.prototype.concat', genMethod(genString)); |
622 argsByAnyFrame('String.prototype.indexOf', genMethod(genString)); | 666 argsByAnyFrame('String.prototype.indexOf', genMethod(genString)); |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 setupTypedArray('Int8Array', true); | 1371 setupTypedArray('Int8Array', true); |
1328 setupTypedArray('Uint8Array', false); | 1372 setupTypedArray('Uint8Array', false); |
1329 setupTypedArray('Uint8ClampedArray', true); | 1373 setupTypedArray('Uint8ClampedArray', true); |
1330 setupTypedArray('Int16Array', false); | 1374 setupTypedArray('Int16Array', false); |
1331 setupTypedArray('Uint16Array', false); | 1375 setupTypedArray('Uint16Array', false); |
1332 setupTypedArray('Int32Array', false); | 1376 setupTypedArray('Int32Array', false); |
1333 setupTypedArray('Uint32Array', true); | 1377 setupTypedArray('Uint32Array', true); |
1334 setupTypedArray('Float32Array', false); | 1378 setupTypedArray('Float32Array', false); |
1335 setupTypedArray('Float64Array', true); | 1379 setupTypedArray('Float64Array', true); |
1336 | 1380 |
1337 obtainInstance.define(cajaVM.intrinsics.TypedArray, new Int8Array(3)); | 1381 obtainInstance.define(cajaVM.anonIntrinsics.TypedArray, new Int8Array(3)); |
1338 argsByIdentity(cajaVM.intrinsics.TypedArray, genAllCall()); | 1382 argsByIdentity(cajaVM.anonIntrinsics.TypedArray, genAllCall()); |
1339 expectedAlwaysThrow.setByIdentity(cajaVM.intrinsics.TypedArray, true); | 1383 expectedAlwaysThrow.setByIdentity(cajaVM.anonIntrinsics.TypedArray, true); |
1340 | 1384 |
1341 argsByAnyFrame('DataView', genNew( | 1385 argsByAnyFrame('DataView', genNew( |
1342 genInstance(ArrayBuffer), genSmallInteger, genSmallInteger)); | 1386 genInstance(ArrayBuffer), genSmallInteger, genSmallInteger)); |
1343 obtainInstance.define(DataView, new DataView(new ArrayBuffer(8))); | 1387 obtainInstance.define(DataView, new DataView(new ArrayBuffer(8))); |
1344 expectedUnfrozen.setByConstructor(DataView, true); | 1388 expectedUnfrozen.setByConstructor(DataView, true); |
1345 var get8 = genMethod(genSmallInteger); | 1389 var get8 = genMethod(genSmallInteger); |
1346 argsByAnyFrame('DataView.prototype.getInt8', get8); | 1390 argsByAnyFrame('DataView.prototype.getInt8', get8); |
1347 argsByAnyFrame('DataView.prototype.getUint8', get8); | 1391 argsByAnyFrame('DataView.prototype.getUint8', get8); |
1348 var getWide = genMethod(genSmallInteger, genBoolean); | 1392 var getWide = genMethod(genSmallInteger, genBoolean); |
1349 argsByAnyFrame('DataView.prototype.getInt16', getWide); | 1393 argsByAnyFrame('DataView.prototype.getInt16', getWide); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 el.className = el.className.replace(/ scan-hide-non-errors/g, ''); | 1625 el.className = el.className.replace(/ scan-hide-non-errors/g, ''); |
1582 } | 1626 } |
1583 hideCheckbox.checked = hide; | 1627 hideCheckbox.checked = hide; |
1584 } | 1628 } |
1585 document.addEventListener('DOMContentLoaded', function() { | 1629 document.addEventListener('DOMContentLoaded', function() { |
1586 hideCheckbox = document.getElementById('hide-non-errors-checkbox'); | 1630 hideCheckbox = document.getElementById('hide-non-errors-checkbox'); |
1587 hideCheckbox.onclick = function() { toggleNonErrors(); }; | 1631 hideCheckbox.onclick = function() { toggleNonErrors(); }; |
1588 }, false); | 1632 }, false); |
1589 window.toggleNonErrors = toggleNonErrors; | 1633 window.toggleNonErrors = toggleNonErrors; |
1590 }()); | 1634 }()); |
LEFT | RIGHT |