Name objects represent reflected namespace::identifier pairs.  Here's
the draft spec.

Comments welcome.

--lars
Title: The class "Name"

The class Name


FILE:                       spec/library/Name.html
DRAFT STATUS:               DRAFT 1 - 2008-03-05
SOURCES:                    REFERENCES [1], [2]
REVIEWED AGAINST ES3:       N/A
REVIEWED AGAINST ERRATA:    N/A
REVIEWED AGAINST BASE DOC:  N/A
REVIEWED AGAINST PROPOSALS: YES
REVIEWED AGAINST CODE:      YES
IMPLEMENTATION STATUS:      ES4 RI


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.

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).

Implementation

public function Name(a, b=undefined)
    : { qualifier: qualifier,
        identifier: identifier } = helper::analyzeArgs(a,b)
{}

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

The Name class object called as a function creates a new Name object by passing its arguments a and b to the Name constructor.

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 {
    if (qualifier === null)
        return identifier;
    return string(qualifier) + "::" + identifier;
}

intrinsic::valueOf ( )

Returns

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

Implementation

override intrinsic function valueOf() : string
    intrinsic::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 delegate to their corresponding intrinsic methods.

Returns

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

Implementation

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

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

Reply via email to