Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
Can't redirect target of freeze operation via preventExtensions trap

Code:

(function () {
    "use strict";

    var proxy;
    var realTarget;
    var target;

    realTarget = {};
    target = {};

    proxy = new Proxy(target, {
        isExtensible: function (target) {
            return Reflect.isExtensible(realTarget);
        },
        preventExtensions: function (target) {
            return Reflect.preventExtensions(realTarget);
        }
    });

    Object.freeze(proxy);
})();

Resulting error message:

[error] Line 20: Uncaught TypeError: 'preventExtensions' on proxy: trap returned truish but the proxy target is extensible

Why is this an error? What's the point of a proxy if I can't redirect this operation?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Proxy traps have a set of so-called invariants they have to conform to.

One of these is that the preventExtensions trap may only return true if [[IsExtensible]] of the proxy's target returns false (i.e. if the target is really made inextensible).

You can work around this by returning false (signaling that making the object inextensible has failed):

preventExtensions: function (target) {
    Reflect.preventExtensions(realTarget);
    return false
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!