Draft 2, changelog near the beginning.

Please note the OPEN ISSUES section, which names two fairly
arbitrary designs in this proposal.  Comments welcome.

--lars

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Lars Hansen
> Sent: 5. mars 2008 17:32
> To: [email protected]
> Subject: ES4 draft: Name
> 
> Name objects represent reflected namespace::identifier pairs. 
>  Here's the draft spec.
> 
> Comments welcome.
> 
> --lars
> 
Title: The class "Name"

The class Name


NAME:                       "The class 'Name'"
FILE:                       spec/library/Name.html
CATEGORY:                   Pre-defined classes
SOURCES:                    REFERENCES [1], [2]
SPEC AUTHOR:                Lars
DRAFT STATUS:               DRAFT 2 - 2008-03-10
REVIEWED AGAINST ES3:       N/A
REVIEWED AGAINST ERRATA:    N/A
REVIEWED AGAINST BASE DOC:  N/A
REVIEWED AGAINST PROPOSALS: YES
REVIEWED AGAINST CODE:      YES
REVIEWED AGAINST TICKETS:   YES
IMPLEMENTATION STATUS:      ES4 RI
TEST CASE STATUS:           ?


CHANGES SINCE DRAFT 1 (2008-03-05)

  * Compatibility note in intro.

  * More elaborate status block above.

  * Prototype and intrinsic methods forward to private methods now.

  * The Name constructor is allowed to hash-cons.

  * The Name converter is required to return its first argument if it
    is a Name object and the second parameter is undefined.


NOTES

  * Due to an RI bug (#368), the namespace 'Private' is used instead
    of 'private'.


OPEN ISSUES

  * intrinsic::valueOf returns a string, but should it return the Name
    object instead?  (The original proposal returns a string.)

  * The constructor accepts combinations of arguments deemed to be
    useful (a convenient but restrained superset of the types in
    EnumerableId).  It's pretty ad-hoc, though.  Any better proposals?


REFERENCES

[1] http://wiki.ecmascript.org/doku.php?id=proposals:name_objects
[2] builtins/Name.es in the ES4 RI

The class Name is a final, nullable, non-dynamic, direct subclass of String that reflects a property name as a pair of Namespace and string values.

COMPATIBILITY NOTE   The Namespace class is new in the 4th Edition of this Standard.

Synopsis

The class Name provides the following interface:

__ES4__ final class Name extends String
{
    public function Name(a, b=undefined) …
    static meta function invoke(a, b=undefined): Name …
    
    public static const length = 2

    override intrinsic function toString() : string …
    override intrinsic function valueOf() : string …

    public const qualifier:  Namespace
    public const identifier: string
}

The Name prototype object provides the following direct properties:

    toString: function (this: Name) …
    valueOf:  function (this: Name) …

Methods on the Name class object

new Name( a, b=… )

Description

The Name constructor initializes a new Name object. Various combinations of the two arguments a and b are allowed. If a is a string, a Name, or an integer in the range [0,232) then b must be undefined. Otherwise, if a is a Namespace then b must be a string or an integer in the range [0,232).

The Name constructor is not required to construct a new, unique object every time it is called.

Implementation

The Name constructor is implementation-dependent.

The helper function analyzeArgs, called by the Name constructor, takes the two values a and b that were passed to the Name constructor and returns an object containing a qualifier in the form of a namespace (which may be null) and an identifier in the form of a string. The qualifier and identifier are used to create the Name object.

static helper function analyzeArgs (a, b) {
    if (a is Namespace)
        return analyzeWithNamespace(a, b);
    if (b === undefined) {
        if (a is Name)
            return a;
        return analyzeWithNamespace(null, a);
    }
    throw new TypeError();

    function analyzeWithNamespace(ns, x) {
        if (x is AnyNumber && isIntegral(x) && x > 0 && x <= 0xFFFFFFFF || x is AnyString)
            return { qualifier: ns, identifier: string(x) };
        throw TypeError();
    }
}

Name (a, b=…)

Description

When the Nameclass object called as a function it creates a Name object. If a is a Name object and b is undefined then a is returned. Otherwise, a Name object is created by invoking the Name constructor on the parameters a and b.

Returns

The Name class object called as a function returns a Name object.

Implementation

static meta function invoke(a, b=undefined): Name
    new Name(a, b);

Methods on Name instances

intrinsic::toString ( )

Description

The intrinsic toString method converts this Name object to a string.

Returns

The intrinsic toString method returns a string.

Implementation

override intrinsic function toString() : string
    Private::toString();

Private function toString() : string {
    if (qualifier === null)
        return identifier;
    return string(qualifier) + "::" + identifier;
}

intrinsic::valueOf ( )

Returns

The intrinsic valueOf method returns what the private toString method returns.

Implementation

override intrinsic function valueOf() : string
    Private::toString();

Value properties of Name instances

qualifier

The qualifier property holds the namespace value for this Name object. It may be null.

identifier

The identifier property holds the identifier value for this Name object. It is never null.

Methods on the Name prototype object

Description

The methods on the Name prototype object perform the same operations as their corresponding intrinsic methods perform.

Returns

The methods on the Name prototype object return what their corresponding intrinsic methods return.

Implementation

prototype function toString(this : Name)
    this.Private::toString();

prototype function valueOf(this : Name)
    this.Private::toString();
_______________________________________________
Es4-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es4-discuss

Reply via email to