Bug 603201 - Enable primitive receivers in [[Get]]. r=jorendorff

This commit is contained in:
Tom Schuster 2015-12-21 23:43:06 +01:00
Родитель 892672a9c9
Коммит 1cd64b091d
8 изменённых файлов: 15 добавлений и 53 удалений

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

@ -199,11 +199,7 @@ Reflect_enumerate(JSContext* cx, unsigned argc, Value* vp)
}
#endif
/*
* ES6 26.1.6 Reflect.get(target, propertyKey [, receiver])
*
* Primitive receivers are not supported yet (see bug 603201).
*/
/* ES6 26.1.6 Reflect.get(target, propertyKey [, receiver]) */
static bool
Reflect_get(JSContext* cx, unsigned argc, Value* vp)
{
@ -221,16 +217,10 @@ Reflect_get(JSContext* cx, unsigned argc, Value* vp)
return false;
// Step 4.
RootedValue receiver(cx, argc > 2 ? args[2] : args.get(0));
// Non-standard hack: Throw a TypeError if the receiver isn't an object.
// See bug 603201.
RootedObject receiverObj(cx, NonNullObject(cx, receiver));
if (!receiverObj)
return false;
RootedValue receiver(cx, args.length() > 2 ? args[2] : args.get(0));
// Step 5.
return GetProperty(cx, obj, receiverObj, key, args.rval());
return GetProperty(cx, obj, receiver, key, args.rval());
}
/* ES6 26.1.7 Reflect.getOwnPropertyDescriptor(target, propertyKey) */
@ -336,7 +326,7 @@ Reflect_set(JSContext* cx, unsigned argc, Value* vp)
return false;
// Step 4.
RootedValue receiver(cx, argc > 3 ? args[3] : args.get(0));
RootedValue receiver(cx, args.length() > 3 ? args[3] : args.get(0));
// Step 5.
ObjectOpResult result;

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

@ -2,9 +2,7 @@
Object.defineProperty(String.prototype, "toLocaleString", {
get() {
// Congratulations! You probably fixed primitive-this getters.
// Change "object" to "string".
assertEq(typeof this, "object");
assertEq(typeof this, "string");
return function() { return typeof this; };
}

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

@ -2,9 +2,7 @@
Object.defineProperty(String.prototype, "toString", {
get() {
// Congratulations! You probably fixed primitive-this getters.
// Change "object" to "string".
assertEq(typeof this, "object");
assertEq(typeof this, "string");
return function() { return typeof this; };
}

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

@ -64,21 +64,8 @@ assertEq(Reflect.get(obj, "itself"), obj);
assertEq(Reflect.get(obj, "itself", Math), Math);
assertEq(Reflect.get(Object.create(obj), "itself", Math), Math);
// The receiver shouldn't have to be an object---but we do not implement that
// correctly yet (bug 603201). For now, test the wrong behavior just to make
// sure we don't crash.
var result;
try {
result = Reflect.get(obj, "x", 37.2);
} catch (exc) {
result = exc;
}
if (result === 37.2) {
throw new Error("Congratulations on fixing bug 603201! " +
"Please update this test for 1 karma point.");
}
assertEq(result instanceof TypeError, true);
// The receiver shouldn't have to be an object
assertEq(Reflect.get(obj, "itself", 37.2), 37.2);
// For more Reflect.get tests, see target.js and propertyKeys.js.

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

@ -20,9 +20,8 @@ Object.defineProperty(Symbol.prototype, "prop", {
get: function () {
"use strict";
gets++;
assertEq(typeof this, "object");
assertEq(this instanceof Symbol, true);
assertEq(this.valueOf(), sym);
assertEq(typeof this, "symbol");
assertEq(this, sym);
return "got";
},
set: function (v) {

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

@ -34,13 +34,6 @@ skip script test262/intl402/ch12/12.2/12.2.2_L15.js
skip script test262/ch13/13.2/13.2-15-1.js
skip script test262/ch11/11.4/11.4.1/11.4.1-5-a-28-s.js
##################################################
# Test262 tests skipped due to SpiderMonkey bugs #
##################################################
skip script test262/ch10/10.4/10.4.3/10.4.3-1-104.js # bug 603201
skip script test262/ch10/10.4/10.4.3/10.4.3-1-106.js # bug 603201
#######################################################################
# Tests disabled due to jstest limitations wrt imported test262 tests #
#######################################################################

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

@ -455,17 +455,15 @@ GetObjectElementOperation(JSContext* cx, JSOp op, JS::HandleObject obj, JS::Hand
}
static MOZ_ALWAYS_INLINE bool
GetPrimitiveElementOperation(JSContext* cx, JSOp op, JS::HandleValue receiver_,
GetPrimitiveElementOperation(JSContext* cx, JSOp op, JS::HandleValue receiver,
HandleValue key, MutableHandleValue res)
{
MOZ_ASSERT(op == JSOP_GETELEM || op == JSOP_CALLELEM);
// FIXME: We shouldn't be boxing here or exposing the boxed object as
// receiver anywhere below (bug 603201).
RootedObject boxed(cx, ToObjectFromStack(cx, receiver_));
// FIXME: Bug 1234324 We shouldn't be boxing here.
RootedObject boxed(cx, ToObjectFromStack(cx, receiver));
if (!boxed)
return false;
RootedValue receiver(cx, ObjectValue(*boxed));
do {
uint32_t index;
@ -495,7 +493,7 @@ GetPrimitiveElementOperation(JSContext* cx, JSOp op, JS::HandleValue receiver_,
RootedId id(cx);
if (!ToPropertyKey(cx, key, &id))
return false;
if (!GetProperty(cx, boxed, boxed, id, res))
if (!GetProperty(cx, boxed, receiver, id, res))
return false;
} while (false);

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

@ -4036,12 +4036,11 @@ js::GetProperty(JSContext* cx, HandleValue v, HandlePropertyName name, MutableHa
return true;
}
RootedValue receiver(cx, v);
RootedObject obj(cx, ToObjectFromStack(cx, v));
if (!obj)
return false;
// Bug 603201: Pass primitive receiver here.
RootedValue receiver(cx, ObjectValue(*obj));
return GetProperty(cx, obj, receiver, name, vp);
}