Bug 1088228 part 2. Create an nsJSUtils API for building the scope chain for a given Element. r=peterv

This commit is contained in:
Boris Zbarsky 2014-10-30 17:40:09 -04:00
Родитель a8f73d5f5b
Коммит 677958f38c
2 изменённых файлов: 29 добавлений и 0 удалений

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

@ -27,6 +27,8 @@
#include "nsContentUtils.h"
#include "nsGlobalWindow.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ScriptSettings.h"
using namespace mozilla::dom;
@ -313,6 +315,27 @@ nsJSUtils::EvaluateString(JSContext* aCx,
options, &unused, aOffThreadToken);
}
/* static */
bool
nsJSUtils::GetScopeChainForElement(JSContext* aCx,
mozilla::dom::Element* aElement,
JS::AutoObjectVector& aScopeChain)
{
for (nsINode* cur = aElement; cur; cur = cur->GetScopeChainParent()) {
JS::RootedValue val(aCx);
if (!WrapNewBindingObject(aCx, cur, &val)) {
return false;
}
if (!aScopeChain.append(&val.toObject())) {
return false;
}
}
return true;
}
//
// nsDOMJSUtils.h
//

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

@ -25,6 +25,7 @@ class nsIScriptGlobalObject;
namespace mozilla {
namespace dom {
class AutoJSAPI;
class Element;
}
}
@ -119,6 +120,11 @@ public:
JS::CompileOptions &aCompileOptions,
void **aOffThreadToken = nullptr);
// Returns false if an exception got thrown on aCx. Passing a null
// aElement is allowed; that wil produce an empty aScopeChain.
static bool GetScopeChainForElement(JSContext* aCx,
mozilla::dom::Element* aElement,
JS::AutoObjectVector& aScopeChain);
};
class MOZ_STACK_CLASS AutoDontReportUncaught {