Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-8223

ES5: Object.freeze throws exception when run on a document

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Won't Fix
    • Affects Version/s: 2.3.2
    • Fix Version/s: None
    • Component/s: JavaScript, Shell
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      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)
             ^

      Show
      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) ^

      Issue Links

        Activity

        • Comments
        Hide
        benjamin.becker Ben Becker (Inactive) added a comment -

        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);

        Show
        benjamin.becker Ben Becker (Inactive) added a comment - 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);

          People

          • Assignee:
            benjamin.becker Ben Becker (Inactive)
            Reporter:
            aheckmann Aaron Heckmann (Inactive)
            Participants:
            Last commenter:
            Ian Whalen
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since reply:
              2 years, 20 weeks, 4 days ago
              Date of 1st Reply: