Closed Bug 547314 Opened 15 years ago Closed 15 years ago

Introduce ObjectOps for typeof

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla1.9.3a2

People

(Reporter: gal, Assigned: gal)

References

(Blocks 1 open bug)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file, 3 obsolete files)

This would make the current code simpler and strictly faster since we already call js_GetWrappedObject, which we wouldn't do any more (the wrapper can unwrapper in the typeof hook). This helps proxies and other non-native objects to masquerade as functions vs objects etc.
I did this on the ssllab.org (UCI research, Andreas's old group) clone of tm. Patch coming up. This suggests to look out for other js_GetWrappedObject callsites and see if they correspond to potential new object-ops. /be
Assignee: general → brendan
Status: NEW → ASSIGNED
OS: Mac OS X → All
Hardware: x86 → All
Target Milestone: --- → mozilla1.9.3a2
This needs tracing support.
This is great! /be
(In reply to comment #4) > This is great! Hah! I updated the wrong bug -- that was meant for bug 547327. /be
Attached patch patch (obsolete) — Splinter Review
Assignee: brendan → gal
Attachment #427868 - Attachment is obsolete: true
Attached patch patch (obsolete) — Splinter Review
Make typeOf a mandatory part of ObjectOps so we can bypass JS_TypeOfValue and always go to obj->typeOf(cx). This might be controversial.
Attachment #428298 - Attachment is obsolete: true
Attachment #428299 - Flags: review?(brendan)
Comment on attachment 428299 [details] [diff] [review] patch >+JSType >+js_TypeOf(JSContext *cx, JSObject *obj) >+{ >+ /* >+ * Wrappers should also intercept js_TypeOf and answer accordingly. >+ */ >+ JS_ASSERT(js_GetWrappedObject(cx, obj) == obj); >+ >+ const JSObjectOps *ops = obj->map->ops; Blank line here, or better: move this down under the comment and above the clasp decl. >+ /* >+ * ECMA 262, 11.4.3 says that any native object that implements >+ * [[Call]] should be of type "function". However, RegExp is of >+ * type "object", not "function", for Web compatibility. >+ */ >+ JSClass *clasp = OBJ_GET_CLASS(cx, obj); >+ if ((ops == &js_ObjectOps) >+ ? (clasp->call >+ ? clasp == &js_ScriptClass >+ : clasp == &js_FunctionClass) >+ : ops->call != NULL) { >+ return JSTYPE_FUNCTION; >+ } else { >+#ifdef NARCISSUS >+ JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED); >+ >+ if (!obj->getProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.__call__Atom), >+ &v)) { Should this use js_GetMethod? Almost certainly, this code (from jsapi.cpp:JS_TypeOfValue) predates that. >+ JS_ClearPendingException(cx); >+ } else if (VALUE_IS_FUNCTION(cx, v)) { >+ return JSTYPE_FUNCTION; >+ } >+#endif >+ } >+ return JSTYPE_OBJECT; >+} >+ > #ifdef JS_THREADSAFE > void > js_DropProperty(JSContext *cx, JSObject *obj, JSProperty *prop) > { > JS_UNLOCK_OBJ(cx, obj); > } > #endif > >diff --git a/js/src/jsobj.h b/js/src/jsobj.h >--- a/js/src/jsobj.h >+++ b/js/src/jsobj.h >@@ -149,16 +149,17 @@ struct JSObjectOps { > JSPropertyIdOp getProperty; > JSPropertyIdOp setProperty; > JSAttributesOp getAttributes; > JSAttributesOp setAttributes; > JSPropertyIdOp deleteProperty; > JSConvertOp defaultValue; > JSNewEnumerateOp enumerate; > JSCheckAccessIdOp checkAccess; >+ JSTypeOfOp typeOf; > > /* Optionally non-null members start here. */ > JSObjectOp thisObject; > JSPropertyRefOp dropProperty; > JSNative call; > JSNative construct; > JSHasInstanceOp hasInstance; > JSTraceOp trace; It looks like trace is no longer optional -- move it up! /be
Attachment #428299 - Flags: review?(brendan) → review+
Attached patch patchSplinter Review
Attachment #428299 - Attachment is obsolete: true
Attachment #428317 - Flags: review?(brendan)
Comment on attachment 428317 [details] [diff] [review] patch Nice -- the make-over (bug 408416) has begun! /be
Attachment #428317 - Flags: review?(brendan) → review+
Blocks: 408416
Whiteboard: fixed-in-tracemonkey
The patch crashes mochitests. All minidumps are useless (awesome, seriously). I am building a fresh build and try to reproduce. If that's not successful soon, I will back out.
We can't bypass unwrapping in the default handler. XOWs don't overwrite object ops (???). Need to talk to Blake about this. http://hg.mozilla.org/tracemonkey/rev/7024444d4ad1
Another follow-up fix. I hit this on facebook. typeof null tried to do (JSObject*)null->typeOf on trace. http://hg.mozilla.org/tracemonkey/rev/6538f7739a9f
Another followup, for an else-after-return nit that broke the common return at exit block structure of JS_TypeOfValue: http://hg.mozilla.org/tracemonkey/rev/2925f17695e3 /be
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Blocks: 566818
No longer blocks: 566818
Depends on: 636446
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: