JavaScript ECMAScript definitions

Discussion in 'Javascript' started by manno, Apr 23, 2004.

  1. manno

    manno Guest

    Hi all,

    more or less just out of curiosity...

    I had a short 'discussion' about JavaScript in different borwsers. The
    other guy said that there's differeces in JavaScript accross browsers (I
    assumed he meant apart from versions) "because there's different
    functions".
    I didn't agree because I think that's because of different DOM's. I know
    that for example IE 5.0 (or 5.5?) does not support array.push() (and a
    lot more), but isn't that just sloppy implementation or simply using
    different versions of the language?

    Is it safe to say that one version of JavaScript should be the same
    everywhere except for DOM differences?

    Is JavaScript ECMA-262 with browserspecific elements?

    Thanks in advance,

    Manno
     
    manno, Apr 23, 2004
    #1
    1. Advertisements

  2. manno wrote:

    Well, array.push is not part of the DOM at all, its a method of the core
    object Array.

    It depends on whom you ask and perhaps it also depends when you ask or
    asked someone.
    With its introduction in the Netscape 2.02 browser there was only one
    implementation of the language and that was in a browser environment but
    there was no ECMAScript standard at all. Later Netscape used its
    JavaScript engine also on the server and documented both client-side
    JavaScript and server-side JavaScript "versions" which consisted of core
    objects specified in ECMAScript and host environment specific objects
    like window, document in client-side JavaScript and server specific
    objects in server-side JavaScript.
    By now Netscape respectively Mozilla has two open-source JavaScript
    engines, one called Spidermonkey implemented in C, the other called
    Rhino imlemented in Java, and there are many different applications that
    use those engines. So you can have JavaScript scripting in many
    environments, not only browser specific ones.
    And the MS JScript scripting engine can also be embedded in many
    different environments, in the IE browser but as well in ASP pages as in
    Windows Script host.
     
    Martin Honnen, Apr 23, 2004
    #2
    1. Advertisements

  3. manno

    manno Guest

    I know the array object's functions are no part of any DOM, I was trying
    to go along in the arguments of the guy I argued with. But to go
    _against_ his argument, is it sloppy implementation or just another
    version of JavaScript that IE 5 version uses?
    That was more or less why I asked, Flash (and the new Director MX 2004)
    support "ECMAScript-compliant JavaScript syntax", I was wondering if
    this actually could be said of browsers too: "Firefox supports
    ECMAScript-compliant JavaScript syntax".

    All with a different 'DOM' ofcourse.

    Thanks
    Manno
     
    manno, Apr 23, 2004
    #3
  4. MS calls its implementation of JavaScript/ECMAScript JScript. I think
    IE5 came with JScript 5 and whether at that time ECMAScript edition 3
    was already out I don't remember exactly, I think Windows 98 already
    featured IE5 while the ECMAScript edition 3 standard came out at the end
    of 1999 thus MS was probably not sloppy in implementing that standard
    but rather focussing on other things and waiting for ECMAScript edition
    3 to be finalized.
     
    Martin Honnen, Apr 23, 2004
    #4
  5. It's JScript, not Javascript. There is no standard for Javascript
    (except perhaps Netscape's documentation for JavaScript).
    What there is, is ECMAScript, as specified by ECMA 262. It is currently
    at version 3. Array.prototype.push was not in ECMA 262 v2, but is in
    v3. It is likely that the versions of JScript shipped with IE 5 was
    based on ECMA 262 v2.
    Sure. And it is just a way of saying "supports ECMAScript" that still
    makes sense for people who think it's all called Javascript.

    /L
     
    Lasse Reichstein Nielsen, Apr 23, 2004
    #5
  6. IE 5.5+ supports array.push(), IE Mac does not.
     
    Java script Dude, Apr 24, 2004
    #6
  7. Somehow I still associate some IE5 release with some Windows 98 release,
    I think there is also Windows 98 second edition (Windows 98 2 ED), maybe
    that came with IE5 and was still out before the ECMAScript edition 3
    specification.
     
    Martin Honnen, Apr 24, 2004
    #7
  8. It is. Nevertheless both JavaScript and JScript are ECMAScript
    implementations (actually, JScript claims to be one while JavaScript is
    one), so they share common objects and methods. However, since objects and
    methods may be (and actually are) implemented differently. ECMAScript is a
    language to be implemented and the language specification makes clear where
    a conforming implementation has certain liberties.
    It executes it anyway, using an engine that supports both JScript and VBScript.


    PointedEars
     
    Thomas 'PointedEars' Lahn, May 3, 2004
    #8
  9. manno

    Jim Ley Guest

    Sorry, why do you claim a distinction, the number of non-conformance
    to the specs is minimal in both implementations, but both
    implementations have them. JavaScript is certainly not a conformant
    implementation any more than JScript is.
    The core Script Engine doesn't support both JScript and VBScript,
    there's a host engine which supports any ActiveScripting language, and
    there's seperate implementations of JScript and VBScript - delete
    vbscript.dll from your windows box and JScript still works fine.

    Jim.
     
    Jim Ley, May 3, 2004
    #9
  10. Two obvious reasons: For example, I know of versions of JScript which yield
    a script error even if one only tests *if* a property exists. In JScript,
    only a function statement with mandatory identifier is specified; the
    "function" operator (allowing for anonymous functions) as defined in
    JavaScript, works anyway. I do not know of similar flaws in JavaScript.
    ACK, thanks.


    PointedEars
     
    Thomas 'PointedEars' Lahn, May 3, 2004
    #10
  11. manno

    Jim Ley Guest

    Sure, but I know of the same in SpiderMonkey impls.
    Sorry, I'm missing what you're trying to say here? it's something
    defined in _JavaScript_ that you're saying isn't in JScript and that's
    a reason to say JScript isn't ECMAScript conformant?
    Just yesterday there was a discussion on the non-conformance of \b in
    RegExps - it was agreed it was a positive non-conformance, but it's
    still not conformant. There are also others.

    Jim.
     
    Jim Ley, May 3, 2004
    #11
  12. And that is a *serious* violation of the ECMAScript specification.
    Tests must be possible, even if they are unsuccessful at last.
    No anonymous functions with "function" keyword and without identifier
    are specified in ECMAScript. JavaScript calls this a "function"
    operator. JScript does not specify this at all, yet it works.


    PointedEars
     
    Thomas 'PointedEars' Lahn, May 3, 2004
    #12
  13. manno

    Randy Webb Guest

    ECMA is a recommendation and nothing more. It reminds me of the W3C.
    Yes, its nice to "comply", but it is not *required*. I would rather
    write/produce code that *works* than code that *complies* but doesn't work.
     
    Randy Webb, May 3, 2004
    #13
  14. manno

    Jim Ley Guest

    Well sure, PIE isn't conformant - hardly news there. (the error also
    only manifests itself with host objects, so it's hardly deadly in the
    real world, and it doesn't happen on real browsers.)
    No, unlike the W3C stuff, ECMAScript is a proper International
    standard. again there's good reasons for not worrying about \b in
    regexps or \ at the end of line or the other minor non-conformances
    though, and the various ES impl's are very much more conformant than
    anything else we get to play with.

    (I still don't understand Thomas's point about function literals, all
    I can see is a complaint against JScript's documentation since "it
    works".

    Jim.
     
    Jim Ley, May 3, 2004
    #14
  15. You are distinguishing between the documentation of JScript and the
    actual implementation. The implementation is ECMAScript conformant.
    The documentation is flawed.

    /L
     
    Lasse Reichstein Nielsen, May 4, 2004
    #15
  16. Yes, I do.
    It is not, but the point is not the documentation issue but, for example,
    the property test issue. I am yet too see something specified that badly
    b0rken in JavaScript.
    Additionally, since it omits important features like this but ibid
    it is stated that JScript is an ECMAScript conforming implementation.


    PointedEars
     
    Thomas 'PointedEars' Lahn, May 4, 2004
    #16
  17. Which test is that? If it is on a host object, then there is no
    guarantee that it should work.
    Well, what's the problem then? That says that function expressions
    work, even if it is not explicitly mentioned anywhere else in the
    JScript documentation. :)

    /L
     
    Lasse Reichstein Nielsen, May 4, 2004
    #17
  18. I have never experienced such a behavior, only read of it (the
    discussion was about the problems of a generic DHTML library):

    ,-<bvc5q3$qh2ii$-berlin.de>
    |
    | [...]
    | Rette mal bei IE4 auf dem Mac blind eine existierende Fenstereigenschaft,
    | der nicht zuvor ein Wert zugewiesen wurde. Dein Rettungsversuch endet mit
    | einer fehlermeldung. Du kannst auch nicht prüfen, ob es etwas zu retten
    | gibt. Allein die Prüfung verursacht schon einen fehler, wenn es nichts zu
    | retten gibt. Bei einem normalen Browser würdest Du einen eventiellen
    | error-Handler retten, Deinen eigenen konnektieren und dann innerhalb
    | Deines eigenen den geretteten aufrufen. Bei IE4 auf dem Mac geht das
    | nicht, wenn es nicht schon einen error-Handler gibt. Genau das aber kannst
    | Du nicht feststellen, ohne einen Fehler zu riskieren. Bugs dieser Art gibt
    | es massenhaft. [...]

    Translation:

    | [...]
    | With IE4 on the Mac, try to make a backup of an existing property of [a]
    | window that has not been assigned a value previously. Your trial results
    | in an error message. You cannot even check if there is something to back
    | up. The check itself results in an error if there is nothing to back up.
    | In a normal browser you would back up a possible error handler, connect
    | your own and then call the backed up one from yours. With IE4 on the
    | Mac this is impossible if there is not already an error handler. But
    | you cannot determine exactly this without risking an error. There are
    | a lot of bugs like this. [...]
    Wrong. Even host objects, if they provide an ECMAScript interface, need to
    exhibit ECMAScript compliant behavior. That is, for example, the mere test
    for a property must not result in a runtime error.


    PointedEars
     
    Thomas 'PointedEars' Lahn, May 5, 2004
    #18
  19. (I am not sure what "an existing property ... that has not been
    assigne a value previously" is ... how do we know it exists if
    we haven't created it, and can't read it?).

    It's highly probable that a browser released in January 1998 doesn't
    implement ECMAScript v3, which was finalized in December 1999.
    In the same way, Netscape's JavaScript 1.2 wasn't ECMAScript compliant
    either.

    However, current versions of JavaScript and JScript are on the same
    level of ECMAScript conformance - almost perfect.

    No. ECMA 262 v3, section 8.6.2 says:
    ---
    Host objects may implement these internal methods with any
    implementation-dependent behaviour, or it may be that a host object
    implements only some internal methods and not others.
    ---
    where "these internal methods" includes [[Get]]. If [[Get]] is undefined,
    then merely testing for a property will give a runtime error.

    With host objects, all bets are off.
    /L
     
    Lasse Reichstein Nielsen, May 5, 2004
    #19
  20. We can write to it and see an effect, I suppose.
    IE for Mac is using JScript which has always claimed to be ECMAScript compliant.
    Well, I had wo workaround the same b0rken behavior with host objects in the
    current IE (JScript 5.6.x).
    Not necessarily. AIUI the "typeof" operator does not call [[Get]] always:

    | 8.7 The Reference Type
    | [...]
    | GetBase(V). Returns the base object component of the reference V.
    | GetPropertyName(V). Returns the property name component of the
    | reference V.

    | 11.4.3 The typeof Operator
    |
    | The production UnaryExpression : typeof UnaryExpression is evaluated as
    | follows:
    |
    | 1. Evaluate UnaryExpression.
    | 2. If Type(Result(1)) is not Reference, go to step 4.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | 3. If GetBase(Result(1)) is null, return "undefined".
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | 4. Call GetValue(Result(1)).
    ^^^^^^^^^^^^^^^^^^^^^^^^
    | 5. Return a string determined by Type(Result(4)) according to the
    | following table:
    | [...]

    | 8.7.1 GetValue (V)
    |
    | 1. If Type(V) is not Reference, return V.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | 2. Call GetBase(V).
    | 3. If Result(2) is null, throw a ReferenceError exception.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | 4. Call the [[Get]] method of Result(2), passing GetPropertyName(V)
    | for the property name.
    | 5. Return Result(4).

    But that operator is available since the first version of JScript:
    No, they are not, at least they *should not*.


    PointedEars
     
    Thomas 'PointedEars' Lahn, May 5, 2004
    #20
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.