Closed Bug 577750 Opened 14 years ago Closed 14 years ago

Get rid of weird checks in js_ComputeGlobalThis

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: mrbkap, Assigned: mrbkap)

References

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file)

Currently, ComputeGlobalThis has:

    if (JSVAL_IS_PRIMITIVE(argv[-2]) || !JSVAL_TO_OBJECT(argv[-2])->getParent()) {
        inner = cx->globalObject;

I don't know how this is possible, though. In global code, we don't have an argv (and we compute this eagerly there anyway) and I don't know why argv[-2] being a global object means we shouldn't use it, but I don't think we should have to support that anyway. In the interests of simplifying this code, we should just be more strict about what we accept/don't accept.
Attached patch patchSplinter Review
This makes it so that you can't have a callable global object (and adds a couple other assertions).
Assignee: general → mrbkap
Status: NEW → ASSIGNED
Attachment #456621 - Flags: review?(jorendorff)
Very cool. BTW, ECMA-262 stipulates that the global object has neither [[Call]] nor [[Construct]] internal methods.

/be
Comment on attachment 456621 [details] [diff] [review]
patch

> JS_SetParent(JSContext *cx, JSObject *obj, JSObject *parent)
> {
>     CHECK_REQUEST(cx);
>+    JS_ASSERT(parent);

Please make this JS_ASSERT(parent || !obj->getParent()) just for compatibility.

> JS_NewGlobalObject(JSContext *cx, JSClass *clasp)
> {
>     CHECK_REQUEST(cx);
>     JS_ASSERT(clasp->flags & JSCLASS_IS_GLOBAL);
>+    JS_ASSERT(!clasp->call);

We don't think this constraint is really necessary, do we? Let's drop it.

Much better! r=me.
Attachment #456621 - Flags: review?(jorendorff) → review+
http://hg.mozilla.org/tracemonkey/rev/4d411039d112
http://hg.mozilla.org/tracemonkey/rev/22502cfcd084 <-- fixes vim-o (deleted the wrong branch in the conditional the first time around).
Whiteboard: fixed-in-tracemonkey
http://hg.mozilla.org/mozilla-central/rev/4d411039d112
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: