e4x weirdness : <toto/>.nodeKind type is not a function

C

cognominal

I am using fifrefox 1.5.0.2 and I have modified the javascript shell
to deal with e4x.
Below is a session. I would have expected <toto/>.nodeKind to be of
type
"function".
Is this right?
Is this conformant to the spec?
Any comments?


$ <toto/>.nodeKind()
element
$ typeof <toto/>.nodeKind
xml
$ typeof function() {}
function
 
T

Thomas 'PointedEars' Lahn

cognominal said:
I am using fifrefox 1.5.0.2 and I have modified the javascript shell
to deal with e4x.

You don't have to modify the JavaScript Shell for that.
For example, I tested with FireBug on Firefox 1.5.0.1/Linux.
Below is a session. I would have expected <toto/>.nodeKind to be of
type
"function".
Is this right?

You are right.
Is this conformant to the spec?

The displayed behavior (typeof <toto/>.nodeKind == "xml") does _not_
conform to ECMA-357. Subsection 7.1.5 (Method Invocation) states:

| object . methodName ( arguments )
|
| where arguments is a comma separated list of zero or more values. The
| method invocation notation is equivalent to constructing a new Reference r
| with base object set to object and property name set to a string literal
| containing the same sequence of characters as methodName, constructing
| an internal list l of the values in arguments, invoking the CallMethod
| operator (section 11.2.2.1) passing r and l as arguments and returning
| the result. [...]

| 1.2.2.1 CallMethod ( r , args )
| [...]
| Given a Reference r and a list of arguments args, the operation CallMethod
| performs the following steps:
|
| 1. Let f = r
| 2. Let base = null
| 3. If Type(r) is Reference
| a. Let base = GetBase(r)
| b. If base == null, throw a ReferenceException
| c. Let P = GetPropertyName(r)
| d. Let f be the result of calling the Object [[Get]] method with
| base as the this object and argument P
| e. If f == undefined and Type(base) is XMLList and
| base.[[Length]] == 1
| i. Let r0 be a new Reference with base object = base[0] and
| property name = P
| ii. Return the result of calling CallMethod(r0, args)
| recursively
| f. If f == undefined and Type(base) is XML and
| base.hasSimpleContent() == true
| i. Let r0 be a new Reference with
| base object = ToObject(ToString(base)) and
| property name = P
| ii. Return the result of calling CallMethod(r0, args)
| recursively
| 4. If Type(f) is not Object, throw a TypeError exception
| 5. If f does not implement the internal [[Call]] method, throw a
| TypeError exception
| 6. If base is an activation object, base = null
| 7. Return the result of calling the [[Call]] method of f providing base
| as the this value and the list args as the argument values

Furthermore:

| 11.3.2 The typeof Operator
|
| [...]
| The production UnaryExpression : typeof UnaryExpression is evaluated as
| follows:
|
| 1. Let u be the result of evaluating UnaryExpression
| 2. If Type(u) is Reference and GetBase(u) is null, return "undefined"
| 3. Return a string determined by Type(GetValue(u)) according to the
| following table:
|
| Type Result
| ---------------------------------
| Undefined "undefined"
| Null "object"
| Boolean "boolean"
| Number "number"
| String "string"
| XML "xml"
| XMLList "xml"
| Object (native and "object"
| doesn't implement
| [[Call]])
| Object (native and "function"
| implements [[Call]])

The last two rows are relevant. We are talking about the built-in
method "nodeKind" (ECMA-357, 13.4.4.25), which is a _native_ Function
_object_ (the Type operator, defined in ECMA-262 Ed. 3 Final would
return Object). Obviously, `<toto/>.nodeKind' could be [[Call]]ed,
to return "element", as specified in subsection 11.1.4 (XML Initialiser).

Therefore, the typeof operation on <toto/>.nodeKind should have
evaluated to "function", not "xml".


PointedEars
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top