[SERVER-8223] ES5: Object.freeze 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
is related to SERVER-8216 ES5: Object.seal throws exception whe... Closed
Operating System: ALL
Steps To Reproduce:

db.u.drop()
db.u.insert({ a: 1 })
var doc = db.u.findOne()
Object.freeze(doc)

throws error

Thu Jan 17 15:18:55.316 javascript execution failed (shell):1 TypeError: Cannot call method 'isWritable' of undefined
Object.freeze(doc)
       ^

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:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.