Bug 621376 - new Function.prototype on trace should not define Function.prototype.prototype. r=brendan

This commit is contained in:
Jeff Walden 2010-12-27 16:24:27 -06:00
parent 001fbb6163
commit ff60a27654
3 changed files with 53 additions and 2 deletions

View File

@ -0,0 +1,22 @@
var funProto = Function.prototype;
assertEq(Object.getOwnPropertyDescriptor(funProto, "prototype"), undefined);
assertEq(parseInt.prototype, undefined);
var oldObj;
for (var i = 0, sz = RUNLOOP; i < sz; oldObj = obj, i++)
{
var obj = new funProto;
assertEq(obj === oldObj, false);
assertEq(Object.prototype.toString.call(obj), "[object Object]");
assertEq(Object.getOwnPropertyDescriptor(funProto, "prototype"), undefined);
assertEq(Object.getOwnPropertyDescriptor(parseInt, "prototype"), undefined);
assertEq(parseInt.prototype, undefined);
}
checkStats({
recorderStarted: 1,
recorderAborted: 0,
traceTriggered: 1,
traceCompleted: 1,
});

View File

@ -0,0 +1,26 @@
var funProto = Function.prototype;
assertEq(Object.getOwnPropertyDescriptor(funProto, "prototype"), undefined);
function Point(x, y) { this.x = x; this.y = y; }
var YAxisPoint = Point.bind(null, 0);
assertEq(YAxisPoint.prototype, undefined);
var oldPoint;
for (var i = 0, sz = RUNLOOP; i < sz; oldPoint = point, i++)
{
var point = new YAxisPoint(5);
assertEq(point === oldPoint, false);
assertEq(point.x, 0);
assertEq(point.y, 5);
assertEq(Object.getOwnPropertyDescriptor(funProto, "prototype"), undefined);
assertEq(Object.getOwnPropertyDescriptor(YAxisPoint, "prototype"), undefined);
}
checkStats({
recorderStarted: 1,
recorderAborted: 1,
traceTriggered: 0,
traceCompleted: 0,
});

View File

@ -2950,8 +2950,11 @@ js_CreateThisFromTrace(JSContext *cx, Class *clasp, JSObject *ctor)
proto = NewNativeClassInstance(cx, clasp, proto, parent);
if (!proto)
return NULL;
if (!js_SetClassPrototype(cx, ctor, proto, JSPROP_ENUMERATE | JSPROP_PERMANENT))
return NULL;
JSFunction *fun = ctor->getFunctionPrivate();
if (!fun->isNative() && !fun->isFunctionPrototype()) {
if (!js_SetClassPrototype(cx, ctor, proto, JSPROP_ENUMERATE | JSPROP_PERMANENT))
return NULL;
}
} else {
/*
* A primitive value in .prototype means to use Object.prototype