Skip to content
  • rswindell's avatar
    Define and use a wrapper for JS_GetInstancePrivate(): js_GetClassPrivate() · 6f83c4ff
    rswindell authored
    Use this in place of JS_GetPrivate() in native class methods that need the
    class instance's private data pointer and will do bad things if that pointer
    points to something other than what is expected. mcmlxxix (matt) discovered
    that using Object.apply(), you can invoke class methods where the 'this'
    instance is a different class. This would result in
    "Internal Error: No Private Data." or a crash.
    So now, gracefully detect this condition and report a meaningful error:
    "'<class-name>' instance: No Private Data or Class Mismatch"
    
    Also, important to note: if the method uses JS_THIS_OBJECT to get the JSObject*
    to pass to JS_Get*Private, then it must do this *before* it calls JS_SET_RVAL.
    
    From jsapi.h:
     * NB: there is an anti-dependency between JS_CALLEE and JS_SET_RVAL: native
     * methods that may inspect their callee must defer setting their return value
     * until after any such possible inspection. Otherwise the return value will be
     * inspected instead of the callee function object.
    
    The js_crypt*.c files still need this treatment.
    6f83c4ff