Browse Source

Getter/setter methods defined in object literal should not have 'prototype' property

Fix following bug:
    var o = {get m() {}};
    var f = Object.getOwnPropertyDescriptor(o, 'm').get;
    console.log(f.hasOwnProperty('prototype')); // expected: false, actual: true
Suwei Chen 9 years ago
parent
commit
8c99d09057

+ 2 - 2
lib/Runtime/Library/JavascriptLibrary.cpp

@@ -4962,13 +4962,13 @@ namespace Js
 #if DEBUG
             if (!function->GetFunctionProxy()->GetIsAnonymousFunction())
             {
-                Assert(!function->GetFunctionInfo()->IsLambda() ?
+                Assert(function->GetFunctionInfo()->IsConstructor() ?
                     function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredPrototypeFunctionTypeHandler(this->GetScriptContext()) :
                     function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredFunctionTypeHandler());
             }
             else
             {
-                Assert(!function->GetFunctionInfo()->IsLambda() ?
+                Assert(function->GetFunctionInfo()->IsConstructor() ?
                     function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredAnonymousPrototypeFunctionTypeHandler() :
                     function->GetDynamicType()->GetTypeHandler() == JavascriptLibrary::GetDeferredAnonymousFunctionTypeHandler());
             }

+ 1 - 1
lib/Runtime/Types/ScriptFunctionType.cpp

@@ -31,7 +31,7 @@ namespace Js
             scriptContext, functionPrototype,
             address,
             proxy->GetDefaultEntryPointInfo(),
-            library->ScriptFunctionTypeHandler(proxy->IsLambda() || proxy->IsAsync() || proxy->IsClassMethod(), proxy->GetIsAnonymousFunction()),
+            library->ScriptFunctionTypeHandler(!proxy->IsConstructor() || proxy->IsAsync() || proxy->IsClassMethod(), proxy->GetIsAnonymousFunction()),
             isShared, isShared);
     }
 };

+ 56 - 43
test/es6/object_literal_bug.js

@@ -1,43 +1,56 @@
-//-------------------------------------------------------------------------------------------------------
-// Copyright (C) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
-//-------------------------------------------------------------------------------------------------------
-
-WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
-
-var tests = [
-  {
-    name: "Object literal shorthand syntax with symbol lookup",
-    body: function () {
-        (function () {
-            let a = 1;
-            {
-                let a = 2;
-                var m = {a};
-                assert.areEqual(m.a, 2, "Name node in object literal shorthand is binding correctly with inner block");
-            }
-        })();
-
-        {
-            let a2 = 1;
-            ({a2} = {a2:2});
-            assert.areEqual(a2, 2, "Destructuring object pattern : Name node in object literal shorthand is binding correctly with inner block");
-        }
-        {
-            // Object literal shorthand - referenced in different scopoe works correctly.
-            { d; }
-
-            {
-                { { d;} };
-                var c = {d};
-            }
-
-            {
-                var d = [];
-            }
-        }
-    }
-  }
-];
-
-testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
+
+var tests = [
+  {
+    name: "Object literal shorthand syntax with symbol lookup",
+    body: function () {
+        (function () {
+            let a = 1;
+            {
+                let a = 2;
+                var m = {a};
+                assert.areEqual(m.a, 2, "Name node in object literal shorthand is binding correctly with inner block");
+            }
+        })();
+
+        {
+            let a2 = 1;
+            ({a2} = {a2:2});
+            assert.areEqual(a2, 2, "Destructuring object pattern : Name node in object literal shorthand is binding correctly with inner block");
+        }
+        {
+            // Object literal shorthand - referenced in different scopoe works correctly.
+            { d; }
+
+            {
+                { { d;} };
+                var c = {d};
+            }
+
+            {
+                var d = [];
+            }
+        }
+    }
+  },
+  {
+    name: "Getter/setter methods defined in object literal should not have 'prototype' property",
+    body: function () {
+        var o = {
+            get m() {},
+            set m(v) {}
+        };
+        var g = Object.getOwnPropertyDescriptor(o, 'm').get;
+        var s = Object.getOwnPropertyDescriptor(o, 'm').set;
+        assert.areEqual(false, g.hasOwnProperty('prototype'), "Getter method defined in object literal should not have 'prototype' property");
+        assert.areEqual(false, s.hasOwnProperty('prototype'), "Setter method defined in object literal should not have 'prototype' property");
+    }
+  },
+];
+
+testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });