Ye olde arguments argument (was: Topic list - pending changes and issues for the ES3.1 spec)

Garrett Smith dhtmlkitchen at gmail.com
Thu Sep 18 21:26:00 PDT 2008


On Wed, Sep 17, 2008 at 7:37 AM, Mike Shaver <mike.shaver at gmail.com> wrote:
> On Wed, Sep 17, 2008 at 3:07 AM, Garrett Smith <dhtmlkitchen at gmail.com> wrote:
>> Instead, it would be more useful for all thrown objects to get a stack
>> property, unless the object already had one.
>
> This has been proposed before in Mozilla, but I and others objected
> because we don't believe that throwing an object should mutate it, and
> because it would cause primitives to be boxed by the property set (or
> have more just-so ad hoc logic that is hard to reason about).
>

While I appreciate the stack property, I disagree on that detail.

If a native object is thrown, and that object is not an Error, then
the either the developer threw it using throw or a Host object threw
it. Right?

If a thrown native object did not already have a stack, what is the
harm in adding one?

Now, if the thrown object already had a stack property then it might
be best to just leave that alone and not replace the value.
A thrown Host object should have a stack property, but doesn't have to
(a DOMException object, for example). calling [[CanPut]](o, "stack"),
prior to adding a stack would allow implementations to have the option
to add a helpful stack property.

throw Error("msg");

- resulting in a stack, or the hypothetically more efficient:-

throw "msg"

Throwing a Host object:

function makeNode(tag) {
  try {
    document.createElement(tag);
  } catch(ex) {
    alert(ex.stack);
  }
}

// Should raise DOMException.
makeNode(':/');

Thoughts?

I can also write up the pseudo-code algorithm steps for review.

> I would be more amenable to have {Syntax,}Error.throwObject(obj)
> provide an Error with stack, and the provided obj as .data or some
> such.

A throwError method. Hmm. How would that work? I guess if the method
were generic, the properties |type| and |message| would not be
changed. Right?

I think |throw| would be easier to spot in source code than
|Error.throwObject|.  My IDE makes |throw| look blue and bold, and it
looks familiar. It would stand out more (at least to me).

Garrett

>
> Mike
>


More information about the Es-discuss mailing list