Example #1
static JSObject *
ResolveInterpretedFunctionPrototype(JSContext *cx, HandleObject obj)
#ifdef DEBUG
    JSFunction *fun = obj->toFunction();

     * Assert that fun is not a compiler-created function object, which
     * must never leak to script or embedding code and then be mutated.
     * Also assert that obj is not bound, per the ES5 ref above.

     * Make the prototype object an instance of Object with the same parent
     * as the function object itself.
    JSObject *objProto = obj->global().getOrCreateObjectPrototype(cx);
    if (!objProto)
        return NULL;
    RootedObject proto(cx, NewObjectWithGivenProto(cx, &ObjectClass, objProto, NULL));
    if (!proto || !proto->setSingletonType(cx))
        return NULL;

     * Per ES5 a user-defined function's .prototype property is
     * initially non-configurable, non-enumerable, and writable.  Per ES5 13.2
     * the prototype's .constructor property is configurable, non-enumerable,
     * and writable.
    RootedValue protoVal(cx, ObjectValue(*proto));
    RootedValue objVal(cx, ObjectValue(*obj));
    if (!obj->defineProperty(cx, cx->runtime->atomState.classPrototypeAtom,
                             protoVal, JS_PropertyStub, JS_StrictPropertyStub,
                             JSPROP_PERMANENT) ||
        !proto->defineProperty(cx, cx->runtime->atomState.constructorAtom,
                               objVal, JS_PropertyStub, JS_StrictPropertyStub, 0))
       return NULL;

    return proto;