object-basic.js 797 B

123456789101112131415161718192021222324252627
  1. try {
  2. var o = { 1: 23, foo: "bar", "hello": "friends" };
  3. assert(o[1] === 23);
  4. assert(o["1"] === 23);
  5. assert(o.foo === "bar");
  6. assert(o["foo"] === "bar");
  7. assert(o.hello === "friends");
  8. assert(o["hello"] === "friends");
  9. o.baz = "test";
  10. assert(o.baz === "test");
  11. assert(o["baz"] === "test");
  12. o[10] = "123";
  13. assert(o[10] === "123");
  14. assert(o["10"] === "123");
  15. o[-1] = "hello friends";
  16. assert(o[-1] === "hello friends");
  17. assert(o["-1"] === "hello friends");
  18. var math = { 3.14: "pi" };
  19. assert(math["3.14"] === "pi");
  20. // Note : this test doesn't pass yet due to floating-point literals being coerced to i32 on access
  21. // assert(math[3.14] === "pi");
  22. console.log("PASS");
  23. } catch (e) {
  24. console.log("FAIL: " + e);
  25. }