Esempio n. 1
0
JSObject*
RegisterPerfMeasurement(JSContext *cx, JSRawObject global)
{
    js::RootedObject prototype(cx);
    prototype = JS_InitClass(cx, global, NULL /* parent */,
                             &pm_class, pm_construct, 1,
                             pm_props, pm_fns, 0, 0);
    if (!prototype)
        return 0;

    js::RootedObject ctor(cx);
    ctor = JS_GetConstructor(cx, prototype);
    if (!ctor)
        return 0;

    for (const pm_const *c = pm_consts; c->name; c++) {
        if (!JS_DefineProperty(cx, ctor, c->name, INT_TO_JSVAL(c->value),
                               JS_PropertyStub, JS_StrictPropertyStub, PM_CATTRS))
            return 0;
    }

    if (!JS_FreezeObject(cx, prototype) ||
        !JS_FreezeObject(cx, ctor)) {
        return 0;
    }

    return prototype;
}
Esempio n. 2
0
JSObject*
RegisterPerfMeasurement(JSContext* cx, HandleObject globalArg)
{
    static const uint8_t PM_CATTRS = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT;

    RootedObject global(cx, globalArg);
    RootedObject prototype(cx);
    prototype = JS_InitClass(cx, global, nullptr /* parent */,
                             &pm_class, pm_construct, 1,
                             pm_props, pm_fns, 0, 0);
    if (!prototype)
        return 0;

    RootedObject ctor(cx);
    ctor = JS_GetConstructor(cx, prototype);
    if (!ctor)
        return 0;

    for (const pm_const* c = pm_consts; c->name; c++) {
        if (!JS_DefineProperty(cx, ctor, c->name, c->value, PM_CATTRS,
                               JS_STUBGETTER, JS_STUBSETTER))
            return 0;
    }

    if (!JS_FreezeObject(cx, prototype) ||
        !JS_FreezeObject(cx, ctor)) {
        return 0;
    }

    return prototype;
}
Esempio n. 3
0
JSDValue*
jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval)
{
    if(!(CHECK_BIT_FLAG(jsdval->flags, GOT_CTOR)))
    {
        JSObject* obj;
        JSObject* proto;
        JSObject* ctor;
        JS_ASSERT(!jsdval->ctor);
        SET_BIT_FLAG(jsdval->flags, GOT_CTOR);
        if(!JSVAL_IS_OBJECT(jsdval->val))
            return NULL;
        if(!(obj = JSVAL_TO_OBJECT(jsdval->val)))
            return NULL;
        JS_BeginRequest(jsdc->dumbContext);
        proto = JS_GetPrototype(jsdc->dumbContext,obj);
        if(!proto)
        {
            JS_EndRequest(jsdc->dumbContext);
            return NULL;
        }
        ctor = JS_GetConstructor(jsdc->dumbContext,proto);
        JS_EndRequest(jsdc->dumbContext);
        if(!ctor)
            return NULL;
        jsdval->ctor = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(ctor));
    }
    if(jsdval->ctor)
        jsdval->ctor->nref++;
    return jsdval->ctor;
}
Esempio n. 4
0
JSDValue*
jsd_GetValueConstructor(JSDContext* jsdc, JSDValue* jsdval)
{
    JSCompartment* oldCompartment = NULL;
    JSContext* cx = jsdc->dumbContext;

    if(!(CHECK_BIT_FLAG(jsdval->flags, GOT_CTOR)))
    {
        JS::RootedObject obj(cx);
        JS::RootedObject proto(cx);
        JS::RootedObject ctor(cx);
        JS_ASSERT(!jsdval->ctor);
        SET_BIT_FLAG(jsdval->flags, GOT_CTOR);
        if(JSVAL_IS_PRIMITIVE(jsdval->val))
            return NULL;
        obj = JSVAL_TO_OBJECT(jsdval->val);
        if(!JS_GetPrototype(cx, obj, proto.address()))
            return NULL;
        if(!proto)
            return NULL;
        JS_BeginRequest(jsdc->dumbContext);
        oldCompartment = JS_EnterCompartment(jsdc->dumbContext, obj);
        ctor = JS_GetConstructor(jsdc->dumbContext,proto);
        JS_LeaveCompartment(jsdc->dumbContext, oldCompartment);
        JS_EndRequest(jsdc->dumbContext);
        if(!ctor)
            return NULL;
        jsdval->ctor = jsd_NewValue(jsdc, OBJECT_TO_JSVAL(ctor));
    }
    if(jsdval->ctor)
        jsdval->ctor->nref++;
    return jsdval->ctor;
}
Esempio n. 5
0
	JSBool init(JSContext* cx, JSObject* scope)
	{ 
		jsPrototype = JS_InitClass(cx, scope, 

			// parent proto
			NULL, 

			&jsClass,

			// native constructor function and min arg count
			constructor, 0,

			// instance properties
			NULL, 

			// instance functions
			instance_functions,

			// static properties
			NULL, 

			// static functions
			static_functions);
			
		jsConstructor = JS_GetConstructor(cx, jsPrototype);
			
		return true;
	}
Esempio n. 6
0
JSObject*
RegisterPerfMeasurement(JSContext *cx, HandleObject globalArg)
{
    RootedObject global(cx, globalArg);
    RootedObject prototype(cx);
    prototype = JS_InitClass(cx, global, js::NullPtr() /* parent */,
                             &pm_class, pm_construct, 1,
                             pm_props, pm_fns, 0, 0);
    if (!prototype)
        return 0;

    RootedObject ctor(cx);
    ctor = JS_GetConstructor(cx, prototype);
    if (!ctor)
        return 0;

    for (const pm_const *c = pm_consts; c->name; c++) {
        if (!JS_DefineProperty(cx, ctor, c->name, c->value, PM_CATTRS,
                               JS_PropertyStub, JS_StrictPropertyStub))
            return 0;
    }

    if (!JS_FreezeObject(cx, prototype) ||
        !JS_FreezeObject(cx, ctor)) {
        return 0;
    }

    return prototype;
}
Esempio n. 7
0
JSObject*
RegisterPerfMeasurement(JSContext *cx, JSObject *global)
{
    JSObject *prototype = JS_InitClass(cx, global, 0 /* parent */,
                                       &pm_class, pm_construct, 1,
                                       pm_props, pm_fns, 0, 0);
    if (!prototype)
        return 0;

    JSObject *ctor = JS_GetConstructor(cx, prototype);
    if (!ctor)
        return 0;

    for (const pm_const *c = pm_consts; c->name; c++) {
        if (!JS_DefineProperty(cx, ctor, c->name, INT_TO_JSVAL(c->value),
                               JS_PropertyStub, JS_PropertyStub, PM_CATTRS))
            return 0;
    }

    if (!JS_SealObject(cx, prototype, JS_FALSE) ||
        !JS_SealObject(cx, ctor, JS_FALSE)) {
        return 0;
    }

    return prototype;
}
Esempio n. 8
0
JSBool
lm_InitEventClasses(MochaDecoder *decoder)
{
    JSContext *cx;
    JSObject *prototype, *ctor;

    cx = decoder->js_context;

    prototype = JS_InitClass(cx, decoder->window_object, NULL, &lm_event_class,
			     lm_Event, 0, event_props, NULL, NULL, NULL);

    if (!prototype|| !(ctor = JS_GetConstructor(cx, prototype)))
	return JS_FALSE;

    if (!JS_DefineConstDoubles(cx, ctor, event_constants))
	return JS_FALSE;

    decoder->event_prototype = prototype;

    prototype = JS_InitClass(cx, decoder->window_object, NULL,
			     &event_receiver_class, EventReceiver, 0,
			     NULL, event_receiver_methods, NULL, NULL);

    if (!prototype)
	return JS_FALSE;
    decoder->event_receiver_prototype = prototype;

    prototype = JS_InitClass(cx, decoder->window_object,
			     decoder->event_receiver_prototype,
			     &event_capturer_class, EventCapturer, 0,
			     NULL, event_capturer_methods, NULL, NULL);


    if (!prototype)
	return JS_FALSE;
    decoder->event_capturer_prototype = prototype;
    return JS_TRUE;
}