summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-24 12:29:12 +0100
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-24 12:29:12 +0100
commit981816155f91e6e74bd2c8f5ac4a3cb5dddb8a86 (patch)
treee037141e417fa6aa63067d65f536f80ace4554b4 /js
parent76aa8d5652a168c73fbdbc0816069361f3434a20 (diff)
downloaduxp-981816155f91e6e74bd2c8f5ac4a3cb5dddb8a86.tar.gz
Bug 1147371: Always decompile argument names in self-hosted code in the caller frame
Issue mcp-graveyard/UXP#74
Diffstat (limited to 'js')
-rw-r--r--js/src/jsopcode.cpp32
1 files changed, 28 insertions, 4 deletions
diff --git a/js/src/jsopcode.cpp b/js/src/jsopcode.cpp
index eadbca4f81..6adb5401ea 100644
--- a/js/src/jsopcode.cpp
+++ b/js/src/jsopcode.cpp
@@ -92,7 +92,8 @@ const char * const js::CodeName[] = {
/************************************************************************/
-#define COUNTS_LEN 16
+static bool
+DecompileArgumentFromStack(JSContext* cx, int formalIndex, char** res);
size_t
js::GetVariableBytecodeLength(jsbytecode* pc)
@@ -1258,6 +1259,24 @@ ExpressionDecompiler::decompilePC(jsbytecode* pc)
return write(loadAtom(pc));
case JSOP_GETARG: {
unsigned slot = GET_ARGNO(pc);
+
+ // For self-hosted scripts that are called from non-self-hosted code,
+ // decompiling the parameter name in the self-hosted script is
+ // unhelpful. Decompile the argument name instead.
+ if (script->selfHosted()) {
+ char* result;
+ if (!DecompileArgumentFromStack(cx, slot, &result))
+ return false;
+
+ // Note that decompiling the argument in the parent frame might
+ // not succeed.
+ if (result) {
+ bool ok = write(result);
+ js_free(result);
+ return ok;
+ }
+ }
+
JSAtom* atom = getArg(slot);
if (!atom)
return false;
@@ -1621,12 +1640,17 @@ DecompileArgumentFromStack(JSContext* cx, int formalIndex, char** res)
MOZ_ASSERT(frameIter.script()->selfHosted());
/*
- * Get the second-to-top frame, the caller of the builtin that called the
- * intrinsic.
+ * Get the second-to-top frame, the non-self-hosted caller of the builtin
+ * that called the intrinsic.
*/
++frameIter;
- if (frameIter.done() || !frameIter.hasScript() || frameIter.compartment() != cx->compartment())
+ if (frameIter.done() ||
+ !frameIter.hasScript() ||
+ frameIter.script()->selfHosted() ||
+ frameIter.compartment() != cx->compartment())
+ {
return true;
+ }
RootedScript script(cx, frameIter.script());
jsbytecode* current = frameIter.pc();