proxytest8.js 1.1 KB

12345678910111213141516171819202122232425
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. var str = new String('testing contains');
  6. var p = new Proxy(str, {});
  7. // Object.defineProperty(p, "toString", {value : function(arg) { print('proxys toString'); return "b"; }});
  8. Object.defineProperty(p, "valueOf", {value : function(arg) { print('proxys valueOf'); return "c"; }});
  9. print(p + "a");
  10. var n = new Number(100);
  11. var p1 = new Proxy(n, {});
  12. Object.defineProperty(p1, "valueOf", {value : function(arg) { print('proxys valueOf'); return 10; }});
  13. print(p1 + 5);
  14. try{
  15. var p2 = new Proxy(new Number(5), {});
  16. p2 + 5;
  17. } catch (e) {
  18. if (!(e instanceof TypeError) || e.message !== "Number.prototype.valueOf: 'this' is not a Number object") {
  19. $ERROR(e);
  20. }
  21. }
  22. print('PASS');