MozReview-Commit-ID: AqsMX4m7Qh9

--HG--
extra : rebase_source : 519aef2cf8c0bb39771d4589069e8fd1a06970c3
This commit is contained in:
Benjamin Bouvier 2016-03-09 11:20:11 +01:00
Родитель 68bd5e8c4d
Коммит 70202e15a1
19 изменённых файлов: 128 добавлений и 26 удалений

Просмотреть файл

@ -502,7 +502,7 @@ nsScriptSecurityManager::ContentSecurityPolicyPermitsJSAction(JSContext *cx)
unsigned lineNum = 0;
NS_NAMED_LITERAL_STRING(scriptSample, "call to eval() or related function blocked by CSP");
JS::UniqueChars scriptFilename;
JS::AutoFilename scriptFilename;
if (JS::DescribeScriptedCaller(cx, &scriptFilename, &lineNum)) {
if (const char *file = scriptFilename.get()) {
CopyUTF8toUTF16(nsDependentCString(file), fileName);

Просмотреть файл

@ -1237,7 +1237,7 @@ WebSocket::Constructor(const GlobalObject& aGlobal,
}
unsigned lineno, column;
JS::UniqueChars file;
JS::AutoFilename file;
if (!JS::DescribeScriptedCaller(aGlobal.Context(), &file, &lineno,
&column)) {
NS_WARNING("Failed to get line number and filename in workers.");
@ -1473,7 +1473,7 @@ WebSocketImpl::Init(JSContext* aCx,
MOZ_ASSERT(aCx);
unsigned lineno, column;
JS::UniqueChars file;
JS::AutoFilename file;
if (JS::DescribeScriptedCaller(aCx, &file, &lineno, &column)) {
mScriptFile = file.get();
mScriptLine = lineno;

Просмотреть файл

@ -10659,7 +10659,7 @@ nsGlobalWindow::ShowSlowScriptDialog()
}
// Check if we should offer the option to debug
JS::UniqueChars filename;
JS::AutoFilename filename;
unsigned lineno;
bool hasFrame = JS::DescribeScriptedCaller(cx, &filename, &lineno);

Просмотреть файл

@ -37,7 +37,7 @@ bool
nsJSUtils::GetCallingLocation(JSContext* aContext, nsACString& aFilename,
uint32_t* aLineno, uint32_t* aColumn)
{
JS::UniqueChars filename;
JS::AutoFilename filename;
if (!JS::DescribeScriptedCaller(aContext, &filename, aLineno, aColumn)) {
return false;
}
@ -50,7 +50,7 @@ bool
nsJSUtils::GetCallingLocation(JSContext* aContext, nsAString& aFilename,
uint32_t* aLineno, uint32_t* aColumn)
{
JS::UniqueChars filename;
JS::AutoFilename filename;
if (!JS::DescribeScriptedCaller(aContext, &filename, aLineno, aColumn)) {
return false;
}

Просмотреть файл

@ -621,7 +621,7 @@ ContentSecurityPolicyAllows(JSContext* aCx)
nsString fileName;
uint32_t lineNum = 0;
JS::UniqueChars file;
JS::AutoFilename file;
if (JS::DescribeScriptedCaller(aCx, &file, &lineNum) && file.get()) {
fileName = NS_ConvertUTF8toUTF16(file.get());
} else {

Просмотреть файл

@ -4296,7 +4296,7 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindowInner* aWindow,
// We're being created outside of a window. Need to figure out the script
// that is creating us in order for us to use relative URIs later on.
JS::UniqueChars fileName;
JS::AutoFilename fileName;
if (JS::DescribeScriptedCaller(aCx, &fileName)) {
// In most cases, fileName is URI. In a few other cases
// (e.g. xpcshell), fileName is a file path. Ideally, we would

Просмотреть файл

@ -907,7 +907,7 @@ void
WorkerDebuggerGlobalScope::ReportError(JSContext* aCx,
const nsAString& aMessage)
{
JS::UniqueChars chars;
JS::AutoFilename chars;
uint32_t lineno = 0;
JS::DescribeScriptedCaller(aCx, &chars, &lineno);
nsString filename(NS_ConvertUTF8toUTF16(chars.get()));

Просмотреть файл

@ -1581,8 +1581,12 @@ wasm::Eval(JSContext* cx, Handle<TypedArrayObject*> code, HandleObject importObj
bytes = copy.begin();
}
UniqueChars file;
if (!DescribeScriptedCaller(cx, &file))
JS::AutoFilename filename;
if (!DescribeScriptedCaller(cx, &filename))
return false;
UniqueChars file = DuplicateString(filename.get());
if (!file)
return false;
ImportNameVector importNames;

Просмотреть файл

@ -2835,7 +2835,7 @@ EvalReturningScope(JSContext* cx, unsigned argc, Value* vp)
size_t srclen = chars.length();
const char16_t* src = chars.start().get();
JS::UniqueChars filename;
JS::AutoFilename filename;
unsigned lineno;
JS::DescribeScriptedCaller(cx, &filename, &lineno);
@ -2921,7 +2921,7 @@ ShellCloneAndExecuteScript(JSContext* cx, unsigned argc, Value* vp)
size_t srclen = chars.length();
const char16_t* src = chars.start().get();
JS::UniqueChars filename;
JS::AutoFilename filename;
unsigned lineno;
JS::DescribeScriptedCaller(cx, &filename, &lineno);

Просмотреть файл

@ -343,6 +343,8 @@ assertEq(wasmEvalText(code.replace('BODY', '(call_import 1)'), imports)(), 2);
assertEq(wasmEvalText(code.replace('BODY', '(call 0)'), imports)(), 3);
assertEq(wasmEvalText(code.replace('BODY', '(call 1)'), imports)(), 4);
assertEq(wasmEvalText(`(module (import "evalcx" "" (param i32) (result i32)) (func (result i32) (call_import 0 (i32.const 0))) (export "" 0))`, {evalcx})(), 0);
var {v2i, i2i, i2v} = wasmEvalText(`(module
(type (func (result i32)))
(type (func (param i32) (result i32)))

Просмотреть файл

@ -6030,8 +6030,51 @@ JS_IsIdentifier(const char16_t* chars, size_t length)
namespace JS {
void AutoFilename::reset()
{
if (ss_) {
reinterpret_cast<ScriptSource*>(ss_)->decref();
ss_ = nullptr;
}
if (filename_.is<const char*>())
filename_.as<const char*>() = nullptr;
else
filename_.as<UniqueChars>().reset();
}
void AutoFilename::setScriptSource(void* p)
{
MOZ_ASSERT(!ss_);
MOZ_ASSERT(!get());
ss_ = p;
if (p) {
ScriptSource* ss = reinterpret_cast<ScriptSource*>(p);
ss->incref();
setUnowned(ss->filename());
}
}
void AutoFilename::setUnowned(const char* filename)
{
MOZ_ASSERT(!get());
filename_.as<const char*>() = filename;
}
void AutoFilename::setOwned(UniqueChars&& filename)
{
MOZ_ASSERT(!get());
filename_ = AsVariant(Move(filename));
}
const char* AutoFilename::get() const
{
if (filename_.is<const char*>())
return filename_.as<const char*>();
return filename_.as<UniqueChars>().get();
}
JS_PUBLIC_API(bool)
DescribeScriptedCaller(JSContext* cx, UniqueChars* filename, unsigned* lineno,
DescribeScriptedCaller(JSContext* cx, AutoFilename* filename, unsigned* lineno,
unsigned* column)
{
if (filename)
@ -6050,11 +6093,18 @@ DescribeScriptedCaller(JSContext* cx, UniqueChars* filename, unsigned* lineno,
if (i.activation()->scriptedCallerIsHidden())
return false;
if (filename && i.filename()) {
UniqueChars copy = DuplicateString(i.filename());
if (!copy)
return false;
*filename = Move(copy);
if (filename) {
if (i.isWasm()) {
// For Wasm, copy out the filename, there is no script source.
UniqueChars copy = DuplicateString(i.filename());
if (!copy)
filename->setUnowned("out of memory");
else
filename->setOwned(Move(copy));
} else {
// All other frames have a script source to read the filename from.
filename->setScriptSource(i.scriptSource());
}
}
if (lineno)

Просмотреть файл

@ -15,6 +15,7 @@
#include "mozilla/Range.h"
#include "mozilla/RangedPtr.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Variant.h"
#include <stdarg.h>
#include <stddef.h>
@ -5408,6 +5409,35 @@ JS_IsIdentifier(const char16_t* chars, size_t length);
namespace JS {
class MOZ_RAII JS_PUBLIC_API(AutoFilename)
{
private:
// Actually a ScriptSource, not put here to avoid including the world.
void* ss_;
mozilla::Variant<const char*, UniqueChars> filename_;
AutoFilename(const AutoFilename&) = delete;
AutoFilename& operator=(const AutoFilename&) = delete;
public:
AutoFilename()
: ss_(nullptr),
filename_(mozilla::AsVariant<const char*>(nullptr))
{}
~AutoFilename() {
reset();
}
void reset();
void setOwned(UniqueChars&& filename);
void setUnowned(const char* filename);
void setScriptSource(void* ss);
const char* get() const;
};
/**
* Return the current filename, line number and column number of the most
* currently running frame. Returns true if a scripted frame was found, false
@ -5417,7 +5447,7 @@ namespace JS {
* record, this will also return false.
*/
extern JS_PUBLIC_API(bool)
DescribeScriptedCaller(JSContext* cx, UniqueChars* filename = nullptr,
DescribeScriptedCaller(JSContext* cx, AutoFilename* filename = nullptr,
unsigned* lineno = nullptr, unsigned* column = nullptr);
extern JS_PUBLIC_API(JSObject*)

Просмотреть файл

@ -113,7 +113,7 @@ ResolvePath(JSContext* cx, HandleString filenameStr, PathResolutionMode resolveM
return filenameStr;
/* Get the currently executing script's name. */
JS::UniqueChars scriptFilename;
JS::AutoFilename scriptFilename;
if (!DescribeScriptedCaller(cx, &scriptFilename))
return nullptr;

Просмотреть файл

@ -2737,7 +2737,7 @@ EvalInContext(JSContext* cx, unsigned argc, Value* vp)
return true;
}
JS::UniqueChars filename;
JS::AutoFilename filename;
unsigned lineno;
DescribeScriptedCaller(cx, &filename, &lineno);
@ -4166,7 +4166,7 @@ ThisFilename(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
JS::UniqueChars filename;
JS::AutoFilename filename;
if (!DescribeScriptedCaller(cx, &filename) || !filename.get()) {
args.rval().setString(cx->runtime()->emptyString);
return true;

Просмотреть файл

@ -880,6 +880,21 @@ FrameIter::functionDisplayAtom() const
MOZ_CRASH("Unexpected state");
}
ScriptSource*
FrameIter::scriptSource() const
{
switch (data_.state_) {
case DONE:
case WASM:
break;
case INTERP:
case JIT:
return script()->scriptSource();
}
MOZ_CRASH("Unexpected state");
}
const char*
FrameIter::filename() const
{

Просмотреть файл

@ -1754,6 +1754,7 @@ class FrameIter
inline bool hasCachedSavedFrame() const;
inline void setHasCachedSavedFrame();
ScriptSource* scriptSource() const;
const char* filename() const;
const char16_t* displayURL() const;
unsigned computeLine(uint32_t* column = nullptr) const;

Просмотреть файл

@ -600,7 +600,7 @@ mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString& url,
nsAutoCString scheme;
// Figure out who's calling us
JS::UniqueChars filename;
JS::AutoFilename filename;
if (!JS::DescribeScriptedCaller(cx, &filename)) {
// No scripted frame means we don't know who's calling, bail.
return NS_ERROR_FAILURE;

Просмотреть файл

@ -141,7 +141,7 @@ GetLocationProperty(JSContext* cx, unsigned argc, Value* vp)
//XXX: your platform should really implement this
return false;
#else
JS::UniqueChars filename;
JS::AutoFilename filename;
if (JS::DescribeScriptedCaller(cx, &filename) && filename.get()) {
nsresult rv;
nsCOMPtr<nsIXPConnect> xpc =

Просмотреть файл

@ -203,7 +203,7 @@ ReportWrapperDenial(JSContext* cx, HandleId id, WrapperDenialType type, const ch
return false;
if (!propertyName.init(cx, str))
return false;
UniqueChars filename;
AutoFilename filename;
unsigned line = 0, column = 0;
DescribeScriptedCaller(cx, &filename, &line, &column);