Closed
Bug 547314
Opened 15 years ago
Closed 15 years ago
Introduce ObjectOps for typeof
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
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)
20.06 KB,
patch
|
brendan
:
review+
|
Details | Diff | Splinter Review |
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.
Assignee | ||
Updated•15 years ago
|
Blocks: harmony:proxies
Comment 1•15 years ago
|
||
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
Updated•15 years ago
|
Assignee: general → brendan
Status: NEW → ASSIGNED
OS: Mac OS X → All
Hardware: x86 → All
Target Milestone: --- → mozilla1.9.3a2
Comment 2•15 years ago
|
||
Assignee | ||
Comment 3•15 years ago
|
||
This needs tracing support.
Comment 4•15 years ago
|
||
This is great! /be
Comment 5•15 years ago
|
||
(In reply to comment #4) > This is great! Hah! I updated the wrong bug -- that was meant for bug 547327. /be
Assignee | ||
Comment 6•15 years ago
|
||
Assignee: brendan → gal
Attachment #427868 -
Attachment is obsolete: true
Assignee | ||
Comment 7•15 years ago
|
||
Make typeOf a mandatory part of ObjectOps so we can bypass JS_TypeOfValue and always go to obj->typeOf(cx). This might be controversial.
Assignee | ||
Updated•15 years ago
|
Attachment #428298 -
Attachment is obsolete: true
Assignee | ||
Updated•15 years ago
|
Attachment #428299 -
Flags: review?(brendan)
Comment 8•15 years ago
|
||
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+
Assignee | ||
Comment 9•15 years ago
|
||
Attachment #428299 -
Attachment is obsolete: true
Assignee | ||
Updated•15 years ago
|
Attachment #428317 -
Flags: review?(brendan)
Comment 10•15 years ago
|
||
Comment on attachment 428317 [details] [diff] [review] patch Nice -- the make-over (bug 408416) has begun! /be
Attachment #428317 -
Flags: review?(brendan) → review+
Assignee | ||
Comment 11•15 years ago
|
||
http://hg.mozilla.org/tracemonkey/rev/65eeef03da7c
Whiteboard: fixed-in-tracemonkey
Assignee | ||
Comment 12•15 years ago
|
||
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.
Assignee | ||
Comment 13•15 years ago
|
||
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
Assignee | ||
Comment 14•15 years ago
|
||
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
Comment 15•15 years ago
|
||
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
Comment 16•15 years ago
|
||
http://hg.mozilla.org/mozilla-central/rev/65eeef03da7c
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•