зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1220031 - Add JS::ubi::Node::scriptFilename; r=sfink
This commit is contained in:
Родитель
fb394133cc
Коммит
704858e786
|
@ -639,6 +639,12 @@ class Base {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Methods for CoarseType::Script referents
|
||||
|
||||
// Return the script's source's filename if available. If unavailable,
|
||||
// return nullptr.
|
||||
virtual const char* scriptFilename() const { return nullptr; }
|
||||
|
||||
private:
|
||||
Base(const Base& rhs) = delete;
|
||||
Base& operator=(const Base& rhs) = delete;
|
||||
|
@ -779,6 +785,8 @@ class Node {
|
|||
return base()->jsObjectConstructorName(cx, outName);
|
||||
}
|
||||
|
||||
const char* scriptFilename() const { return base()->scriptFilename(); }
|
||||
|
||||
using Size = Base::Size;
|
||||
Size size(mozilla::MallocSizeOf mallocSizeof) const {
|
||||
return base()->size(mallocSizeof);
|
||||
|
@ -1052,6 +1060,7 @@ struct Concrete<JS::Symbol> : TracerConcrete<JS::Symbol> {
|
|||
template<> struct Concrete<JSScript> : TracerConcreteWithCompartment<JSScript> {
|
||||
CoarseType coarseType() const final { return CoarseType::Script; }
|
||||
Size size(mozilla::MallocSizeOf mallocSizeOf) const override;
|
||||
const char* scriptFilename() const final;
|
||||
|
||||
protected:
|
||||
explicit Concrete(JSScript *ptr) : TracerConcreteWithCompartment<JSScript>(ptr) { }
|
||||
|
|
|
@ -782,6 +782,7 @@ namespace ubi {
|
|||
template<>
|
||||
struct Concrete<js::jit::JitCode> : TracerConcrete<js::jit::JitCode> {
|
||||
CoarseType coarseType() const final { return CoarseType::Script; }
|
||||
|
||||
Size size(mozilla::MallocSizeOf mallocSizeOf) const override {
|
||||
Size size = js::gc::Arena::thingSize(get().asTenured().getAllocKind());
|
||||
size += get().bufferSize();
|
||||
|
|
|
@ -346,3 +346,37 @@ BEGIN_TEST(test_ubiPostOrder)
|
|||
return true;
|
||||
}
|
||||
END_TEST(test_ubiPostOrder)
|
||||
|
||||
BEGIN_TEST(test_JS_ubi_Node_scriptFilename)
|
||||
{
|
||||
JS::RootedValue val(cx);
|
||||
CHECK(evaluate("(function one() { \n" // 1
|
||||
" return (function two() { \n" // 2
|
||||
" return (function three() { \n" // 3
|
||||
" return function four() {}; \n" // 4
|
||||
" }()); \n" // 5
|
||||
" }()); \n" // 6
|
||||
"}()); \n", // 7
|
||||
"my-cool-filename.js",
|
||||
1,
|
||||
&val));
|
||||
|
||||
CHECK(val.isObject());
|
||||
JS::RootedObject obj(cx, &val.toObject());
|
||||
|
||||
CHECK(obj->is<JSFunction>());
|
||||
JS::RootedFunction func(cx, &obj->as<JSFunction>());
|
||||
|
||||
JS::RootedScript script(cx, func->getOrCreateScript(cx));
|
||||
CHECK(script);
|
||||
CHECK(script->filename());
|
||||
|
||||
JS::ubi::Node node(script);
|
||||
const char* filename = node.scriptFilename();
|
||||
CHECK(filename);
|
||||
CHECK(strcmp(filename, script->filename()) == 0);
|
||||
CHECK(strcmp(filename, "my-cool-filename.js") == 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
END_TEST(test_JS_ubi_Node_scriptFilename)
|
||||
|
|
|
@ -4406,6 +4406,12 @@ JS::ubi::Concrete<JSScript>::size(mozilla::MallocSizeOf mallocSizeOf) const
|
|||
return size;
|
||||
}
|
||||
|
||||
const char*
|
||||
JS::ubi::Concrete<JSScript>::scriptFilename() const
|
||||
{
|
||||
return get().filename();
|
||||
}
|
||||
|
||||
JS::ubi::Node::Size
|
||||
JS::ubi::Concrete<js::LazyScript>::size(mozilla::MallocSizeOf mallocSizeOf) const
|
||||
{
|
||||
|
@ -4413,3 +4419,17 @@ JS::ubi::Concrete<js::LazyScript>::size(mozilla::MallocSizeOf mallocSizeOf) cons
|
|||
size += get().sizeOfExcludingThis(mallocSizeOf);
|
||||
return size;
|
||||
}
|
||||
|
||||
const char*
|
||||
JS::ubi::Concrete<js::LazyScript>::scriptFilename() const
|
||||
{
|
||||
auto sourceObject = get().sourceObject();
|
||||
if (!sourceObject)
|
||||
return nullptr;
|
||||
|
||||
auto source = sourceObject->source();
|
||||
if (!source)
|
||||
return nullptr;
|
||||
|
||||
return source->filename();
|
||||
}
|
||||
|
|
|
@ -2487,6 +2487,7 @@ template<>
|
|||
struct Concrete<js::LazyScript> : TracerConcrete<js::LazyScript> {
|
||||
CoarseType coarseType() const final { return CoarseType::Script; }
|
||||
Size size(mozilla::MallocSizeOf mallocSizeOf) const override;
|
||||
const char* scriptFilename() const final;
|
||||
|
||||
protected:
|
||||
explicit Concrete(js::LazyScript *ptr) : TracerConcrete<js::LazyScript>(ptr) { }
|
||||
|
|
Загрузка…
Ссылка в новой задаче