Bug 1075294 - Object.seal() should return its argument with no conversion when the argument is a primitive value. r=till
authorziyunfei <446240525@qq.com>
Wed, 01 Oct 2014 04:30:00 +0200
changeset 208215 0d9b59a1d80bc2930856f98ede7a8d89cb262239
parent 208214 0a308311d9a7dd6bbbf0be74cd2956cd90e8016b
child 208216 a45d02c3b4e848a798996ae9c575c1137ca320ca
push id27580
push userkwierso@gmail.com
push dateWed, 01 Oct 2014 23:26:55 +0000
treeherderautoland@af6c928893c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs1075294
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1075294 - Object.seal() should return its argument with no conversion when the argument is a primitive value. r=till
js/src/builtin/Object.cpp
js/src/tests/ecma_6/Object/seal.js
--- a/js/src/builtin/Object.cpp
+++ b/js/src/builtin/Object.cpp
@@ -840,17 +840,17 @@ js::obj_getOwnPropertyDescriptor(JSConte
 }
 
 // ES6 draft rev25 (2014/05/22) 19.1.2.14 Object.keys(O)
 static bool
 obj_keys(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
-    // steps 1-2
+    // Steps 1-2.
     RootedObject obj(cx);
     if (!GetFirstArgumentAsObject(cx, args, "Object.keys", &obj))
         return false;
 
     // Steps 3-10. Since JSITER_SYMBOLS and JSITER_HIDDEN are not passed,
     // GetPropertyNames performs the type check in step 10.c. and the
     // [[Enumerable]] check specified in step 10.c.iii.
     AutoIdVector props(cx);
@@ -868,17 +868,17 @@ obj_keys(JSContext *cx, unsigned argc, V
         } else {
             str = Int32ToString<CanGC>(cx, JSID_TO_INT(id));
             if (!str)
                 return false;
         }
         namelist.infallibleAppend(StringValue(str));
     }
 
-    // step 11
+    // Step 11.
     JS_ASSERT(props.length() <= UINT32_MAX);
     JSObject *aobj = NewDenseCopiedArray(cx, uint32_t(namelist.length()), namelist.begin());
     if (!aobj)
         return false;
 
     args.rval().setObject(*aobj);
     return true;
 }
@@ -914,27 +914,27 @@ js::IdToStringOrSymbol(JSContext *cx, Ha
 }
 
 namespace js {
 
 /* ES6 draft rev 25 (2014 May 22) 19.1.2.8.1 */
 bool
 GetOwnPropertyKeys(JSContext *cx, const JS::CallArgs &args, unsigned flags)
 {
-    // steps 1-2
+    // Steps 1-2.
     RootedObject obj(cx, ToObject(cx, args.get(0)));
     if (!obj)
         return false;
 
-    // steps 3-10
+    // Steps 3-10.
     AutoIdVector keys(cx);
     if (!GetPropertyNames(cx, obj, flags, &keys))
         return false;
 
-    // step 11
+    // Step 11.
     AutoValueVector vals(cx);
     if (!vals.resize(keys.length()))
         return false;
 
     for (size_t i = 0, len = keys.length(); i < len; i++) {
         MOZ_ASSERT_IF(JSID_IS_SYMBOL(keys[i]), flags & JSITER_SYMBOLS);
         MOZ_ASSERT_IF(!JSID_IS_SYMBOL(keys[i]), !(flags & JSITER_SYMBOLSONLY));
         if (!IdToStringOrSymbol(cx, keys[i], vals[i]))
@@ -1016,41 +1016,41 @@ obj_defineProperties(JSContext *cx, unsi
 }
 
 // ES6 draft rev27 (2014/08/24) 19.1.2.11 Object.isExtensible(O)
 static bool
 obj_isExtensible(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
-    // step 1
+    // Step 1.
     bool extensible = false;
 
-    // step 2
+    // Step 2.
     if (args.get(0).isObject()) {
         RootedObject obj(cx, &args.get(0).toObject());
         if (!JSObject::isExtensible(cx, obj, &extensible))
             return false;
     }
     args.rval().setBoolean(extensible);
     return true;
 }
 
 // ES6 draft rev27 (2014/08/24) 19.1.2.15 Object.preventExtensions(O)
 static bool
 obj_preventExtensions(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
     args.rval().set(args.get(0));
 
-    // step 1
+    // Step 1.
     if (!args.get(0).isObject())
         return true;
 
-    // steps 2-5
+    // Steps 2-5.
     RootedObject obj(cx, &args.get(0).toObject());
 
     return JSObject::preventExtensions(cx, obj);
 }
 
 static bool
 obj_freeze(JSContext *cx, unsigned argc, Value *vp)
 {
@@ -1065,52 +1065,55 @@ obj_freeze(JSContext *cx, unsigned argc,
 }
 
 // ES6 draft rev27 (2014/08/24) 19.1.2.12 Object.isFrozen(O)
 static bool
 obj_isFrozen(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
-    // step 1
+    // Step 1.
     bool frozen = true;
 
-    // step 2
+    // Step 2.
     if (args.get(0).isObject()) {
         RootedObject obj(cx, &args.get(0).toObject());
         if (!JSObject::isFrozen(cx, obj, &frozen))
             return false;
     }
     args.rval().setBoolean(frozen);
     return true;
 }
 
+// ES6 draft rev27 (2014/08/24) 19.1.2.17 Object.seal(O)
 static bool
 obj_seal(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
-    RootedObject obj(cx);
-    if (!GetFirstArgumentAsObject(cx, args, "Object.seal", &obj))
-        return false;
+    args.rval().set(args.get(0));
 
-    args.rval().setObject(*obj);
+    // Step 1.
+    if (!args.get(0).isObject())
+        return true;
 
+    // Steps 2-5.
+    RootedObject obj(cx, &args.get(0).toObject());
     return JSObject::seal(cx, obj);
 }
 
 // ES6 draft rev27 (2014/08/24) 19.1.2.13 Object.isSealed(O)
 static bool
 obj_isSealed(JSContext *cx, unsigned argc, Value *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
 
-    // step 1
+    // Step 1.
     bool sealed = true;
 
-    // step 2
+    // Step 2.
     if (args.get(0).isObject()) {
         RootedObject obj(cx, &args.get(0).toObject());
         if (!JSObject::isSealed(cx, obj, &sealed))
             return false;
     }
     args.rval().setBoolean(sealed);
     return true;
 }
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/Object/seal.js
@@ -0,0 +1,21 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * https://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+var BUGNUMBER = 1075294;
+var summary = "Object.seal() should return its argument with no conversion when the argument is a primitive value";
+
+print(BUGNUMBER + ": " + summary);
+assertEq(Object.seal(), undefined);
+assertEq(Object.seal(undefined), undefined);
+assertEq(Object.seal(null), null);
+assertEq(Object.seal(1), 1);
+assertEq(Object.seal("foo"), "foo");
+assertEq(Object.seal(true), true);
+if (typeof Symbol === "function") {
+    assertEq(Object.seal(Symbol.for("foo")), Symbol.for("foo"));
+}
+
+if (typeof reportCompare === "function")
+    reportCompare(true, true);