If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

defineProperty seems to not comply with standard browser JS behavior

UNCONFIRMED
Unassigned

Status

Rhino
Core
UNCONFIRMED
3 years ago
3 years ago

People

(Reporter: Henry Minsky, Unassigned)

Tracking

Details

Attachments

(1 attachment)

138.55 KB, text/javascript
Details
(Reporter)

Description

3 years ago
Created attachment 8551748 [details]
Intl.js

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.69 Safari/537.36

Steps to reproduce:

I am trying to run the Intl.js library , which implements the new Intl.NumberFormat feature. (I should file another bug that Intl is not part of Rhino yet)

https://github.com/andyearnshaw/Intl.js/




Actual results:

The Intl.js library gets an exception when loading. 

The error happens at this line
    /* 11.3.2 */$$core$$defineProperty($$core$$Intl.NumberFormat.prototype, 'format', {
        configurable: true,
        get: $$core$$GetFormatNumber
    });


Which is a compatibility patch for trying to make defineProperty work like standard browsers

    var $$core$$Intl = {},

        $$core$$realDefineProp = (function () {
            try { return !!Object.defineProperty({}, 'a', {}); }
            catch (e) { return false; }
        })(),

        // Need a workaround for getters in ES3
        $$core$$es3  = !$$core$$realDefineProp && !Object.prototype.__defineGetter__,

        // We use this a lot (and need it for proto-less objects)
        $$core$$hop = Object.prototype.hasOwnProperty,

        // Naive defineProperty for compatibility
        $$core$$defineProperty = $$core$$realDefineProp ? Object.defineProperty : function (obj, name, desc) {
            if ('get' in desc && obj.__defineGetter__)
                obj.__defineGetter__(name, desc.get);

            else if (!$$core$$hop.call(obj, name) || 'value' in desc)
                obj[name] = desc.value;
        },






Expected results:

Library Intl.js should have loaded without error

The workaround is to modify the Intl.js function which probes the system implementatin of defineProperty

        $$core$$realDefineProp = (function () {
//            try { return !!Object.defineProperty({}, 'a', {}); }
//            catch (e) { return false; }
         return false;
        })(),


To force it to not use the builtin defineProperty at all, and use the workaround version in the file. This is not desirable though, as there are regression tests which expect to be able to set read-only properties on objects, and those no longer work.
(Reporter)

Comment 1

3 years ago
This behavior is seen in 1.7R3 and 1.7R4. 

Even if I try running with -version 180, it gets the same bug with defineProperty
You need to log in before you can comment on or make changes to this bug.