author Igor Bukanov <igor@mir2.org>
Mon, 19 Mar 2012 15:27:58 +0100
changeset 89777 ca0782c1f3d5deb2986793580662a11e07935dd7
parent 87967 9dde6af30ab201c2fdb0084e298182533eac48ff
child 90352 e89811e547a2145155457f1a987078a2cf72ff60
permissions -rw-r--r--
bug 736978 - remove JS_FinalizeStub. r=:billm Currently the GC finalizes on the background thread only objects with null JSClass::finalize. However, this implies that any object that uses JS_FinalizeStub for the finalizer would be prevented from the background finalization. To fix this the patch removes JS_FinalizeStub replacing it with NULL in all cases when the class has no custom finalizer. For style consistency the patch also removed the usage of JSCLASS_NO_OPTIONAL_MEMBERS in the static declarations as the compiler fills the missing fields with null in any cases.

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=8 sw=4 et tw=99:
 * Tests the JSClass::getProperty hook

#include "tests.h"

int called_test_fn;
int called_test_prop_get;

static JSBool test_prop_get( JSContext *cx, JSObject *obj, jsid id, jsval *vp )
    return JS_TRUE;

static JSBool
PTest(JSContext* cx, unsigned argc, jsval *vp)
    JSObject *obj = JS_NewObjectForConstructor(cx, vp);
    if (!obj)
        return JS_FALSE;
    JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
    return JS_TRUE;

static JSClass ptestClass = {

    JS_PropertyStub,       // add
    JS_PropertyStub,       // delete
    test_prop_get,         // get
    JS_StrictPropertyStub, // set

static JSBool test_fn(JSContext *cx, unsigned argc, jsval *vp)
    return JS_TRUE;

static JSFunctionSpec ptestFunctions[] = {
    JS_FS( "test_fn", test_fn, 0, 0 ),

    CHECK(JS_InitClass(cx, JS_GetGlobalObject(cx), NULL, &ptestClass, PTest, 0,
                       NULL, ptestFunctions, NULL, NULL));

    EXEC("function check() { var o = new PTest(); o.test_fn(); o.test_value1; o.test_value2; o.test_value1; }");

    for (int i = 1; i < 9; i++) {
        jsvalRoot rval(cx);
        CHECK(JS_CallFunctionName(cx, global, "check", 0, NULL, rval.addr()));
        CHECK_SAME(INT_TO_JSVAL(called_test_fn), INT_TO_JSVAL(i));
        CHECK_SAME(INT_TO_JSVAL(called_test_prop_get), INT_TO_JSVAL(4 * i));
    return true;