Skip to content

Commit

Permalink
Bug 1140428 - Warn when __noSuchMethod__ is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
rmottola committed Apr 3, 2019
1 parent ed89197 commit 976c938
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions js/src/jscompartment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ JSCompartment::JSCompartment(Zone* zone, const JS::CompartmentOptions& options =
isSystem(false),
isSelfHosting(false),
marked(true),
warnedAboutNoSuchMethod(false),
addonId(options.addonIdOrNull()),
#ifdef DEBUG
firedOnNewGlobalObject(false),
Expand Down
1 change: 1 addition & 0 deletions js/src/jscompartment.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ struct JSCompartment
bool isSystem;
bool isSelfHosting;
bool marked;
bool warnedAboutNoSuchMethod;

// A null add-on ID means that the compartment is not associated with an
// add-on.
Expand Down
23 changes: 14 additions & 9 deletions js/src/vm/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,32 +179,37 @@ js::OnUnknownMethod(JSContext* cx, HandleObject obj, Value idval_, MutableHandle
}

static bool
NoSuchMethod(JSContext* cx, unsigned argc, Value* vp)
NoSuchMethod(JSContext *cx, unsigned argc, Value *vp)
{
if (JSScript *script = cx->currentScript()) {
const char *filename = script->filename();
cx->compartment()->addTelemetry(filename, JSCompartment::DeprecatedNoSuchMethod);
}

if (!cx->compartment()->warnedAboutNoSuchMethod) {
if (!JS_ReportWarning(cx, "__noSuchMethod__ is deprecated"))
return false;
cx->compartment()->warnedAboutNoSuchMethod = true;
}

InvokeArgs args(cx);
if (!args.init(2))
return false;

MOZ_ASSERT(vp[0].isObject());
MOZ_ASSERT(vp[1].isObject());
NativeObject* obj = &vp[0].toObject().as<NativeObject>();
NativeObject *obj = &vp[0].toObject().as<NativeObject>();
MOZ_ASSERT(obj->getClass() == &js_NoSuchMethodClass);

args.setCallee(obj->getReservedSlot(JSSLOT_FOUND_FUNCTION));
args.setThis(vp[1]);
args[0].set(obj->getReservedSlot(JSSLOT_SAVED_ID));
JSObject* argsobj = NewDenseCopiedArray(cx, argc, vp + 2);
JSObject *argsobj = NewDenseCopiedArray(cx, argc, vp + 2);
if (!argsobj)
return false;
args[1].setObject(*argsobj);
bool ok = Invoke(cx, args);
vp[0] = args.rval();

if (JSScript* script = cx->currentScript()) {
const char* filename = script->filename();
cx->compartment()->addTelemetry(filename, JSCompartment::DeprecatedNoSuchMethod);
}

return ok;
}

Expand Down

0 comments on commit 976c938

Please sign in to comment.