Bug 1140428 - Warn when __noSuchMethod__ is used. r=jorendorff

This commit is contained in:
Jan de Mooij 2015-03-12 13:07:02 +01:00
parent a36bc65522
commit 90e561ba19
3 changed files with 13 additions and 6 deletions

View File

@ -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),

View File

@ -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.

View File

@ -180,6 +180,17 @@ js::OnUnknownMethod(JSContext *cx, HandleObject obj, Value idval_, MutableHandle
static bool
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;
@ -198,12 +209,6 @@ NoSuchMethod(JSContext *cx, unsigned argc, Value *vp)
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;
}