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

Reflect.parse: support builder methods that are callable but not JSFunctions

NEW
Unassigned

Status

()

Core
JavaScript Engine
4 years ago
3 years ago

People

(Reporter: jorendorff, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

4 years ago
The following doesn't work in a Browser Scratchpad:

Components.utils.import("resource://gre/modules/reflect.jsm") ;
Reflect.parse("42", { builder: {
  program: function program() {
    return 24;
  }
}});

It gives the error "(function program() {
    return 24;
  }) is not a function".

This is because what is actually passed to Reflect.parse is a transparent wrapper around the builder object, triggering this code in NodeBuilder::init:

            if (!funv.isObject() || !funv.toObject().is<JSFunction>()) {
                js_ReportValueErrorFlags(cx, JSREPORT_ERROR, JSMSG_NOT_FUNCTION,
                                         JSDVG_SEARCH_STACK, funv, js::NullPtr(), nullptr, nullptr);
                return false;
            }

Transparent wrappers around JSFunctions are not JSFunctions.

Reported by Florent Fayolle.
(Reporter)

Comment 1

4 years ago
Here is a workaround for Florent:

Components.classes["@mozilla.org/jsreflect;1"].createInstance()();
Reflect.parse("42", { builder: {
  program: function program() {
    return 24;
  }
}});

Comment 2

4 years ago
Many thanks Jason for the workaround!

Florent
(Assignee)

Updated

3 years ago
Assignee: general → nobody
You need to log in before you can comment on or make changes to this bug.