/ Ticket Change Details

Artifact ID: 950a3f88010664f58f6e036b727b09383db1dc79
Ticket: 5e4ee9db1c419e948321ad42c92b5d4a8687f802
number as object key
User & Date: pmacdona 2019-04-16 04:54:02

  1. Change icomment to:

    For objects there are 3 notations at play here:

    1. obj.X = Y;
    2. obj[X] = Y;
    3. obj = {X:Y};

    And yes indeed V8 does coerces the LHS of {X:Y} in 3 to a string, while Jsi does not.

    However, what's at play is really a fundamental philosophical difference:

    • V8 treats arrays as objects with keys like "1", "2",..., whereas
    • Jsi implements real arrays indexed by integers

    An example where this may seem wrong in Jsi is:

        # var x = [];
        # x['abc'] = 1;
        # x
        # x.keys()
        # x.abc

    "Why do this" might you ask?

    One reason is that arrays are more efficient in Jsi because the do not store the key. Another is CData structs, where some fields are C arrays. Then there are function parameter types, where arrays and objects are different. (for giggles see line 100 of ./file/lib/web/jsiweb.js where in V8 we try to figure out types where everything is an object).

    Lastly, why does Jsi accept obj[X]=Y where X is a number? It's quite simple actually: at compile time the parser has no way of knowing if obj is an array or an object.

    I've rambled on enough. How about we sleep on this for tonight, and for now reduce this to important

  2. Change login to "pmacdona"
  3. Change mimetype to "text/x-fossil-wiki"
  4. Change priority to "Immediate"
  5. Change resolution to "Open"
  6. Change severity to "Important"
  7. Change subsystem to "Javascript"