[SERVER-8216] ES5: Object.seal throws exception when run on a document Created: 17/Jan/13  Updated: 19/May/14  Resolved: 14/Feb/13

Status: Closed
Project: Core Server
Component/s: JavaScript, Shell
Affects Version/s: 2.3.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Aaron Heckmann Assignee: Ben Becker
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-8223 ES5: Object.freeze throws exception w... Closed
Operating System: ALL
Steps To Reproduce:

db.u.drop()
db.u.insert({x:1})
var x = db.u.findOne()
Object.seal(x)

throws

Thu Jan 17 12:31:05.156 javascript execution failed (shell):1 TypeError: Cannot call method 'isConfigurable' of undefined
Object.seal(x)
       ^

Note: simply accessing each property of the document or iterating it before sealing is enough to prevent the error from occuring.

 

db.u.drop()
db.u.insert(

{x:1}

)
var x = db.u.findOne()
for (var p in x) {}
Object.seal; // no longer throws

Participants:

 Comments   
Comment by Ben Becker [ 14/Feb/13 ]

It seems that the current version of v8 using doesn't support various ES5 features like Object.freeze() and Object.seal() when the object was instantiated from an ObjectTemplate with NamedPropertyHandlers.

However, these appear to work once the properties of an object have been accessed:

for (var i in x) { }
// - or -
Object.keys\(x).forEach(function(p){x[p]});

A simple hack exemplifying this case:

diff --git a/src/third_party/v8/src/v8natives.js b/src/third_party/v8/src/v8natives.js
index e2e6429..b75c1cc 100644
--- a/src/third_party/v8/src/v8natives.js
+++ b/src/third_party/v8/src/v8natives.js
@@ -978,6 +978,7 @@ function ObjectGetOwnPropertyNames(obj) {
   if (!IS_SPEC_OBJECT(obj)) {
     throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
   }
+  for (var i in obj) {}
   // Special handling for proxies.
   if (%IsJSProxy(obj)) {
     var handler = %GetHandler(obj);

Generated at Thu Feb 08 03:16:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.