Bug 671091 - Add DefinePropertiesAndBrand to abstract out most explicit branding. NOT REVIEWED YET

--HG--
extra : rebase_source : 9a48fc83a876c95e90c807eb0b007d35211eb41c
This commit is contained in:
Jeff Walden 2011-06-15 10:15:37 -07:00
Родитель 649e39d0f6
Коммит b3dc7a728e
5 изменённых файлов: 22 добавлений и 27 удалений

Просмотреть файл

@ -3838,23 +3838,12 @@ DefineConstructorAndPrototype(JSContext *cx, JSObject *obj, JSProtoKey key, JSAt
ctor->setProto(proto); ctor->setProto(proto);
} }
/* Add properties and methods to the prototype and the constructor. */ if (!DefinePropertiesAndBrand(cx, proto, ps, fs) ||
if ((ps && !JS_DefineProperties(cx, proto, ps)) || (ctor != proto && !DefinePropertiesAndBrand(cx, ctor, static_ps, static_fs)))
(fs && !JS_DefineFunctions(cx, proto, fs)) || {
(static_ps && !JS_DefineProperties(cx, ctor, static_ps)) ||
(static_fs && !JS_DefineFunctions(cx, ctor, static_fs))) {
goto bad; goto bad;
} }
/*
* Pre-brand the prototype and constructor if they have built-in methods.
* This avoids extra shape guard branch exits in the tracejitted code.
*/
if (fs)
proto->brand(cx);
if (ctor != proto && static_fs)
ctor->brand(cx);
/* /*
* Make sure proto's emptyShape is available to be shared by objects of * Make sure proto's emptyShape is available to be shared by objects of
* this class. JSObject::emptyShape is a one-slot cache. If we omit this, * this class. JSObject::emptyShape is a one-slot cache. If we omit this,

Просмотреть файл

@ -841,13 +841,8 @@ js_InitRegExpClass(JSContext *cx, JSObject *obj)
if (!proto->initRegExp(cx, re.get())) if (!proto->initRegExp(cx, re.get()))
return NULL; return NULL;
/* if (!DefinePropertiesAndBrand(cx, proto, NULL, regexp_methods))
* Now add the standard methods to RegExp.prototype, and pre-brand for
* better shape-guarding code.
*/
if (!JS_DefineFunctions(cx, proto, regexp_methods))
return NULL; return NULL;
proto->brand(cx);
JSFunction *ctor = global->createConstructor(cx, regexp_construct, &js_RegExpClass, JSFunction *ctor = global->createConstructor(cx, regexp_construct, &js_RegExpClass,
CLASS_ATOM(cx, RegExp), 2); CLASS_ATOM(cx, RegExp), 2);

Просмотреть файл

@ -3185,17 +3185,12 @@ js_InitStringClass(JSContext *cx, JSObject *obj)
if (!LinkConstructorAndPrototype(cx, ctor, proto)) if (!LinkConstructorAndPrototype(cx, ctor, proto))
return NULL; return NULL;
/* Add properties and methods to the prototype and the constructor. */ if (!DefinePropertiesAndBrand(cx, proto, NULL, string_methods) ||
if (!JS_DefineFunctions(cx, proto, string_methods) || !DefinePropertiesAndBrand(cx, ctor, NULL, string_static_methods))
!JS_DefineFunctions(cx, ctor, string_static_methods))
{ {
return NULL; return NULL;
} }
/* Pre-brand String and String.prototype for trace-jitted code. */
proto->brand(cx);
ctor->brand(cx);
if (!DefineConstructorAndPrototype(cx, global, JSProto_String, ctor, proto)) if (!DefineConstructorAndPrototype(cx, global, JSProto_String, ctor, proto))
return NULL; return NULL;

Просмотреть файл

@ -252,4 +252,13 @@ LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto)
ObjectValue(*ctor), PropertyStub, StrictPropertyStub, 0); ObjectValue(*ctor), PropertyStub, StrictPropertyStub, 0);
} }
bool
DefinePropertiesAndBrand(JSContext *cx, JSObject *obj, JSPropertySpec *ps, JSFunctionSpec *fs)
{
if ((ps && !JS_DefineProperties(cx, obj, ps)) || (fs && !JS_DefineFunctions(cx, obj, fs)))
return false;
obj->brand(cx);
return true;
}
} // namespace js } // namespace js

Просмотреть файл

@ -177,6 +177,13 @@ class GlobalObject : public ::JSObject {
extern bool extern bool
LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto); LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto);
/*
* Define properties, then functions, on the object, then brand for tracing
* benefits.
*/
extern bool
DefinePropertiesAndBrand(JSContext *cx, JSObject *obj, JSPropertySpec *ps, JSFunctionSpec *fs);
} // namespace js } // namespace js
js::GlobalObject * js::GlobalObject *