Bug 1009675 part 3. Return WebIDL 'object' values as handles. r=peterv

This commit is contained in:
Boris Zbarsky 2014-06-11 16:26:52 -04:00
Родитель bc1e511e33
Коммит dfe8c38082
32 изменённых файлов: 228 добавлений и 166 удалений

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

@ -2087,9 +2087,10 @@ public:
const nsAString& aTypeExtension,
uint32_t aNamespaceID,
mozilla::ErrorResult& rv) = 0;
virtual JSObject*
virtual void
RegisterElement(JSContext* aCx, const nsAString& aName,
const mozilla::dom::ElementRegistrationOptions& aOptions,
JS::MutableHandle<JSObject*> aRetval,
mozilla::ErrorResult& rv) = 0;
/**

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

@ -5767,14 +5767,15 @@ nsDocument::sProcessingStack;
bool
nsDocument::sProcessingBaseElementQueue;
JSObject*
void
nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
const ElementRegistrationOptions& aOptions,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& rv)
{
if (!mRegistry) {
rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return nullptr;
return;
}
Registry::DefinitionMap& definitions = mRegistry->mCustomDefinitions;
@ -5795,7 +5796,7 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
nsCOMPtr<nsIAtom> typeAtom(do_GetAtom(lcType));
if (!nsContentUtils::IsCustomElementName(typeAtom)) {
rv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return nullptr;
return;
}
// If there already exists a definition with the same TYPE, set ERROR to
@ -5804,13 +5805,13 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
CustomElementHashKey duplicateFinder(kNameSpaceID_Unknown, typeAtom);
if (definitions.Get(&duplicateFinder)) {
rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return nullptr;
return;
}
nsIGlobalObject* sgo = GetScopeObject();
if (!sgo) {
rv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
return;
}
JS::Rooted<JSObject*> global(aCx, sgo->GetGlobalJSObject());
@ -5820,7 +5821,7 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
HTMLElementBinding::GetProtoObject(aCx, global));
if (!htmlProto) {
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
return;
}
int32_t namespaceID = kNameSpaceID_XHTML;
@ -5829,7 +5830,7 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
protoObject = JS_NewObject(aCx, nullptr, htmlProto, JS::NullPtr());
if (!protoObject) {
rv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
return;
}
} else {
// If a prototype is provided, we must check to ensure that it is from the
@ -5837,7 +5838,7 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
protoObject = aOptions.mPrototype;
if (JS_GetGlobalForObject(aCx, protoObject) != global) {
rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return nullptr;
return;
}
// If PROTOTYPE is already an interface prototype object for any interface
@ -5846,27 +5847,27 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
const js::Class* clasp = js::GetObjectClass(protoObject);
if (IsDOMIfaceAndProtoClass(clasp)) {
rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return nullptr;
return;
}
JS::Rooted<JSPropertyDescriptor> descRoot(aCx);
JS::MutableHandle<JSPropertyDescriptor> desc(&descRoot);
if (!JS_GetPropertyDescriptor(aCx, protoObject, "constructor", desc)) {
rv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
return;
}
// Check if non-configurable
if (desc.isPermanent()) {
rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return nullptr;
return;
}
JS::Handle<JSObject*> svgProto(
SVGElementBinding::GetProtoObject(aCx, global));
if (!svgProto) {
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
return;
}
JS::Rooted<JSObject*> protoProto(aCx, protoObject);
@ -5885,7 +5886,7 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
if (!JS_GetPrototype(aCx, protoProto, &protoProto)) {
rv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
return;
}
}
}
@ -5900,7 +5901,7 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
nsIParserService* ps = nsContentUtils::GetParserService();
if (!ps) {
rv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
return;
}
known =
@ -5914,13 +5915,13 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
// If BASE exists, then it cannot be an interface for a custom element.
if (!known) {
rv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return nullptr;
return;
}
} else {
// If NAMESPACE is SVG Namespace, set ERROR to InvalidName and stop.
if (namespaceID == kNameSpaceID_SVG) {
rv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
return;
}
nameAtom = typeAtom;
@ -5929,7 +5930,8 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
nsAutoPtr<LifecycleCallbacks> callbacksHolder(new LifecycleCallbacks());
JS::RootedValue rootedv(aCx, JS::ObjectValue(*protoObject));
if (!callbacksHolder->Init(aCx, rootedv)) {
return nullptr;
rv.Throw(NS_ERROR_FAILURE);
return;
}
// Associate the definition with the custom element.
@ -5988,8 +5990,12 @@ nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
JSFunction* constructor = JS_NewFunction(aCx, nsDocument::CustomElementConstructor, 0,
JSFUN_CONSTRUCTOR, JS::NullPtr(),
NS_ConvertUTF16toUTF8(lcType).get());
JSObject* constructorObject = JS_GetFunctionObject(constructor);
return constructorObject;
if (!constructor) {
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
aRetval.set(JS_GetFunctionObject(constructor));
}
void

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

@ -1226,9 +1226,10 @@ public:
// WebIDL bits
virtual mozilla::dom::DOMImplementation*
GetImplementation(mozilla::ErrorResult& rv) MOZ_OVERRIDE;
virtual JSObject*
virtual void
RegisterElement(JSContext* aCx, const nsAString& aName,
const mozilla::dom::ElementRegistrationOptions& aOptions,
JS::MutableHandle<JSObject*> aRetval,
mozilla::ErrorResult& rv) MOZ_OVERRIDE;
virtual mozilla::dom::StyleSheetList* StyleSheets() MOZ_OVERRIDE;
virtual void SetSelectedStyleSheetSet(const nsAString& aSheetSet) MOZ_OVERRIDE;

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

@ -1267,8 +1267,9 @@ CanvasRenderingContext2D::SetTransform(double m11, double m12,
mTarget->SetTransform(matrix);
}
JSObject*
MatrixToJSObject(JSContext* cx, const Matrix& matrix, ErrorResult& error)
static void
MatrixToJSObject(JSContext* cx, const Matrix& matrix,
JS::MutableHandle<JSObject*> result, ErrorResult& error)
{
double elts[6] = { matrix._11, matrix._12,
matrix._21, matrix._22,
@ -1278,10 +1279,9 @@ MatrixToJSObject(JSContext* cx, const Matrix& matrix, ErrorResult& error)
JS::Rooted<JS::Value> val(cx);
if (!ToJSValue(cx, elts, &val)) {
error.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
} else {
result.set(&val.toObject());
}
return &val.toObject();
}
static bool
@ -1334,11 +1334,13 @@ CanvasRenderingContext2D::SetMozCurrentTransform(JSContext* cx,
}
}
JSObject*
void
CanvasRenderingContext2D::GetMozCurrentTransform(JSContext* cx,
JS::MutableHandle<JSObject*> result,
ErrorResult& error) const
{
return MatrixToJSObject(cx, mTarget ? mTarget->GetTransform() : Matrix(), error);
MatrixToJSObject(cx, mTarget ? mTarget->GetTransform() : Matrix(),
result, error);
}
void
@ -1361,12 +1363,14 @@ CanvasRenderingContext2D::SetMozCurrentTransformInverse(JSContext* cx,
}
}
JSObject*
void
CanvasRenderingContext2D::GetMozCurrentTransformInverse(JSContext* cx,
JS::MutableHandle<JSObject*> result,
ErrorResult& error) const
{
if (!mTarget) {
return MatrixToJSObject(cx, Matrix(), error);
MatrixToJSObject(cx, Matrix(), result, error);
return;
}
Matrix ctm = mTarget->GetTransform();
@ -1376,7 +1380,7 @@ CanvasRenderingContext2D::GetMozCurrentTransformInverse(JSContext* cx,
ctm = Matrix(NaN, NaN, NaN, NaN, NaN, NaN);
}
return MatrixToJSObject(cx, ctm, error);
MatrixToJSObject(cx, ctm, result, error);
}
//

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

@ -388,13 +388,15 @@ public:
void Arc(double x, double y, double radius, double startAngle,
double endAngle, bool anticlockwise, mozilla::ErrorResult& error);
JSObject* GetMozCurrentTransform(JSContext* cx,
mozilla::ErrorResult& error) const;
void GetMozCurrentTransform(JSContext* cx,
JS::MutableHandle<JSObject*> result,
mozilla::ErrorResult& error) const;
void SetMozCurrentTransform(JSContext* cx,
JS::Handle<JSObject*> currentTransform,
mozilla::ErrorResult& error);
JSObject* GetMozCurrentTransformInverse(JSContext* cx,
mozilla::ErrorResult& error) const;
void GetMozCurrentTransformInverse(JSContext* cx,
JS::MutableHandle<JSObject*> result,
mozilla::ErrorResult& error) const;
void SetMozCurrentTransformInverse(JSContext* cx,
JS::Handle<JSObject*> currentTransform,
mozilla::ErrorResult& error);

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

@ -61,9 +61,9 @@ public:
{
return mHeight;
}
JSObject* Data(JSContext* cx) const
void GetData(JSContext* cx, JS::MutableHandle<JSObject*> aData) const
{
return GetDataObject();
aData.set(GetDataObject());
}
JSObject* GetDataObject() const
{

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

@ -285,7 +285,9 @@ public:
void GetContextAttributes(dom::Nullable<dom::WebGLContextAttributes>& retval);
bool IsContextLost() const { return mContextStatus != ContextNotLost; }
void GetSupportedExtensions(JSContext *cx, dom::Nullable< nsTArray<nsString> > &retval);
JSObject* GetExtension(JSContext* cx, const nsAString& aName, ErrorResult& rv);
void GetExtension(JSContext* cx, const nsAString& aName,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& rv);
void ActiveTexture(GLenum texture);
void AttachShader(WebGLProgram* program, WebGLShader* shader);
void BindAttribLocation(WebGLProgram* program, GLuint location,

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

@ -182,11 +182,15 @@ CompareWebGLExtensionName(const nsACString& name, const char *other)
return name.Equals(other, nsCaseInsensitiveCStringComparator());
}
JSObject*
WebGLContext::GetExtension(JSContext *cx, const nsAString& aName, ErrorResult& rv)
void
WebGLContext::GetExtension(JSContext *cx, const nsAString& aName,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& rv)
{
if (IsContextLost())
return nullptr;
if (IsContextLost()) {
aRetval.set(nullptr);
return;
}
NS_LossyConvertUTF16toASCII name(aName);
@ -235,12 +239,14 @@ WebGLContext::GetExtension(JSContext *cx, const nsAString& aName, ErrorResult& r
}
if (ext == WebGLExtensionID::Unknown) {
return nullptr;
aRetval.set(nullptr);
return;
}
// step 2: check if the extension is supported
if (!IsExtensionSupported(cx, ext)) {
return nullptr;
aRetval.set(nullptr);
return;
}
// step 3: if the extension hadn't been previously been created, create it now, thus enabling it
@ -248,7 +254,7 @@ WebGLContext::GetExtension(JSContext *cx, const nsAString& aName, ErrorResult& r
EnableExtension(ext);
}
return WebGLObjectAsJSObject(cx, mExtensions[ext].get(), rv);
aRetval.set(WebGLObjectAsJSObject(cx, mExtensions[ext].get(), rv));
}
void

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

@ -529,7 +529,8 @@ public:
return mAudioCaptured;
}
JSObject* MozGetMetadata(JSContext* aCx, ErrorResult& aRv);
void MozGetMetadata(JSContext* aCx, JS::MutableHandle<JSObject*> aResult,
ErrorResult& aRv);
double MozFragmentEnd();

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

@ -1673,18 +1673,20 @@ HTMLMediaElement::BuildObjectFromTags(nsCStringHashKey::KeyType aKey,
return PL_DHASH_NEXT;
}
JSObject*
HTMLMediaElement::MozGetMetadata(JSContext* cx, ErrorResult& aRv)
void
HTMLMediaElement::MozGetMetadata(JSContext* cx,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv)
{
if (mReadyState < nsIDOMHTMLMediaElement::HAVE_METADATA) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return nullptr;
return;
}
JS::Rooted<JSObject*> tags(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
if (!tags) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
return;
}
if (mTags) {
MetadataIterCx iter = {cx, tags, false};
@ -1692,19 +1694,19 @@ HTMLMediaElement::MozGetMetadata(JSContext* cx, ErrorResult& aRv)
if (iter.error) {
NS_WARNING("couldn't create metadata object!");
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
return;
}
}
return tags;
aRetval.set(tags);
}
NS_IMETHODIMP
HTMLMediaElement::MozGetMetadata(JSContext* cx, JS::MutableHandle<JS::Value> aValue)
{
ErrorResult rv;
JSObject* obj = MozGetMetadata(cx, rv);
JS::Rooted<JSObject*> obj(cx);
MozGetMetadata(cx, &obj, rv);
if (!rv.Failed()) {
MOZ_ASSERT(obj);
aValue.setObject(*obj);

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

@ -2244,15 +2244,17 @@ nsHTMLDocument::ResolveName(const nsAString& aName, nsWrapperCache **aCache)
return nullptr;
}
JSObject*
void
nsHTMLDocument::NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& rv)
{
nsWrapperCache* cache;
nsISupports* supp = ResolveName(aName, &cache);
if (!supp) {
aFound = false;
return nullptr;
aRetval.set(nullptr);
return;
}
JS::Rooted<JS::Value> val(cx);
@ -2260,10 +2262,10 @@ nsHTMLDocument::NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
// here?
if (!dom::WrapObject(cx, supp, cache, nullptr, &val)) {
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
return;
}
aFound = true;
return &val.toObject();
aRetval.set(&val.toObject());
}
bool

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

@ -174,8 +174,9 @@ public:
void SetDomain(const nsAString& aDomain, mozilla::ErrorResult& rv);
void GetCookie(nsAString& aCookie, mozilla::ErrorResult& rv);
void SetCookie(const nsAString& aCookie, mozilla::ErrorResult& rv);
JSObject* NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
mozilla::ErrorResult& rv);
void NamedGetter(JSContext* cx, const nsAString& aName, bool& aFound,
JS::MutableHandle<JSObject*> aRetval,
mozilla::ErrorResult& rv);
bool NameIsEnumerable(const nsAString& aName);
void GetSupportedNames(unsigned, nsTArray<nsString>& aNames);
nsGenericHTMLElement *GetBody();

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

@ -99,8 +99,10 @@ MediaKeyMessageEvent::Constructor(const GlobalObject& aGlobal,
return e.forget();
}
JSObject*
MediaKeyMessageEvent::GetMessage(JSContext* cx, ErrorResult& aRv)
void
MediaKeyMessageEvent::GetMessage(JSContext* cx,
JS::MutableHandle<JSObject*> aMessage,
ErrorResult& aRv)
{
if (!mMessage) {
mMessage = Uint8Array::Create(cx,
@ -109,12 +111,12 @@ MediaKeyMessageEvent::GetMessage(JSContext* cx, ErrorResult& aRv)
mRawMessage.Elements());
if (!mMessage) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
return;
}
mRawMessage.Clear();
}
JS::ExposeObjectToActiveJS(mMessage);
return mMessage;
aMessage.set(mMessage);
}
void

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

@ -50,7 +50,9 @@ public:
const MediaKeyMessageEventInit& aEventInitDict,
ErrorResult& aRv);
JSObject* GetMessage(JSContext* cx, ErrorResult& aRv);
void GetMessage(JSContext* cx,
JS::MutableHandle<JSObject*> aMessage,
ErrorResult& aRv);
void GetDestinationURL(nsString& aRetVal) const;

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

@ -94,8 +94,10 @@ MediaKeyNeededEvent::GetInitDataType(nsString& aRetVal) const
aRetVal = mInitDataType;
}
JSObject*
MediaKeyNeededEvent::GetInitData(JSContext* cx, ErrorResult& aRv)
void
MediaKeyNeededEvent::GetInitData(JSContext* cx,
JS::MutableHandle<JSObject*> aData,
ErrorResult& aRv)
{
if (mRawInitData.Length()) {
mInitData = Uint8Array::Create(cx,
@ -104,14 +106,14 @@ MediaKeyNeededEvent::GetInitData(JSContext* cx, ErrorResult& aRv)
mRawInitData.Elements());
if (!mInitData) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
return;
}
mRawInitData.Clear();
}
if (mInitData) {
JS::ExposeObjectToActiveJS(mInitData);
}
return mInitData;
aData.set(mInitData);
}
} // namespace dom

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

@ -51,7 +51,9 @@ public:
void GetInitDataType(nsString& aRetVal) const;
JSObject* GetInitData(JSContext* cx, ErrorResult& aRv);
void GetInitData(JSContext* cx,
JS::MutableHandle<JSObject*> aData,
ErrorResult& aRv);
private:
nsTArray<uint8_t> mRawInitData;
};

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

@ -192,21 +192,25 @@ AudioBuffer::SetRawChannelContents(uint32_t aChannel, float* aContents)
PodCopy(JS_GetFloat32ArrayData(mJSChannels[aChannel]), aContents, mLength);
}
JSObject*
void
AudioBuffer::GetChannelData(JSContext* aJSContext, uint32_t aChannel,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv)
{
if (aChannel >= NumberOfChannels()) {
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return nullptr;
return;
}
if (!RestoreJSChannelData(aJSContext)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
return;
}
return mJSChannels[aChannel];
if (mJSChannels[aChannel]) {
JS::ExposeObjectToActiveJS(mJSChannels[aChannel]);
}
aRetval.set(mJSChannels[aChannel]);
}
static already_AddRefed<ThreadSharedFloatArrayBufferList>

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

@ -74,8 +74,9 @@ public:
* If mSharedChannels is non-null, copies its contents to
* new Float32Arrays in mJSChannels. Returns a Float32Array.
*/
JSObject* GetChannelData(JSContext* aJSContext, uint32_t aChannel,
ErrorResult& aRv);
void GetChannelData(JSContext* aJSContext, uint32_t aChannel,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv);
void CopyFromChannel(const Float32Array& aDestination, uint32_t aChannelNumber,
uint32_t aStartInChannel, ErrorResult& aRv);

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

@ -27,9 +27,12 @@ public:
virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE;
JSObject* GetCurve(JSContext* aCx) const
void GetCurve(JSContext* aCx, JS::MutableHandle<JSObject*> aRetval) const
{
return mCurve;
if (mCurve) {
JS::ExposeObjectToActiveJS(mCurve);
}
aRetval.set(mCurve);
}
void SetCurve(const Nullable<Float32Array>& aData);

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

@ -55,8 +55,9 @@ Crypto::WrapObject(JSContext* aCx)
return CryptoBinding::Wrap(aCx, this);
}
JSObject *
void
Crypto::GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Called on the wrong thread");
@ -76,17 +77,18 @@ Crypto::GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray,
break;
default:
aRv.Throw(NS_ERROR_DOM_TYPE_MISMATCH_ERR);
return nullptr;
return;
}
aArray.ComputeLengthAndData();
uint32_t dataLen = aArray.Length();
if (dataLen == 0) {
NS_WARNING("ArrayBufferView length is 0, cannot continue");
return view;
aRetval.set(view);
return;
} else if (dataLen > 65536) {
aRv.Throw(NS_ERROR_DOM_QUOTA_EXCEEDED_ERR);
return nullptr;
return;
}
uint8_t* data = aArray.Data();
@ -98,7 +100,7 @@ Crypto::GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray,
if (!cc->SendGetRandomValues(dataLen, &randomValues) ||
randomValues.Length() == 0) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
return;
}
NS_ASSERTION(dataLen == randomValues.Length(),
"Invalid length returned from parent process!");
@ -108,14 +110,14 @@ Crypto::GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray,
if (!buf) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
return;
}
memcpy(data, buf, dataLen);
NS_Free(buf);
}
return view;
aRetval.set(view);
}
SubtleCrypto*

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

@ -41,8 +41,9 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Crypto)
JSObject *
void
GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv);
SubtleCrypto*

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

@ -3929,45 +3929,48 @@ nsGlobalWindow::GetRealTop(nsIDOMWindow** aTop)
return GetTopImpl(outer, aTop, /* aScriptable = */ false);
}
JSObject*
nsGlobalWindow::GetContent(JSContext* aCx, ErrorResult& aError)
void
nsGlobalWindow::GetContent(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aError)
{
FORWARD_TO_OUTER_OR_THROW(GetContent, (aCx, aError), aError, nullptr);
FORWARD_TO_OUTER_OR_THROW(GetContent, (aCx, aRetval, aError), aError, );
nsCOMPtr<nsIDOMWindow> content = GetContentInternal(aError);
if (aError.Failed()) {
return nullptr;
return;
}
if (content) {
JS::Rooted<JS::Value> val(aCx);
aError = nsContentUtils::WrapNative(aCx, content, &val);
if (aError.Failed()) {
return nullptr;
return;
}
return &val.toObject();
aRetval.set(&val.toObject());
return;
}
if (!nsContentUtils::IsCallerChrome() || !IsChromeWindow()) {
aError.Throw(NS_ERROR_FAILURE);
return nullptr;
return;
}
// Something tries to get .content on a ChromeWindow, try to fetch the CPOW.
nsCOMPtr<nsIDocShellTreeOwner> treeOwner = GetTreeOwner();
if (!treeOwner) {
aError.Throw(NS_ERROR_FAILURE);
return nullptr;
return;
}
JS::Rooted<JS::Value> val(aCx, JS::NullValue());
aError = treeOwner->GetContentWindow(aCx, &val);
if (aError.Failed()) {
return nullptr;
return;
}
return val.toObjectOrNull();
aRetval.set(val.toObjectOrNull());
}
already_AddRefed<nsIDOMWindow>
@ -4035,7 +4038,8 @@ NS_IMETHODIMP
nsGlobalWindow::GetScriptableContent(JSContext* aCx, JS::MutableHandle<JS::Value> aVal)
{
ErrorResult rv;
JS::Rooted<JSObject*> content(aCx, GetContent(aCx, rv));
JS::Rooted<JSObject*> content(aCx);
GetContent(aCx, &content, rv);
if (!rv.Failed()) {
aVal.setObjectOrNull(content);
}

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

@ -991,13 +991,17 @@ public:
const nsAString& aOptions,
const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
mozilla::ErrorResult& aError);
JSObject* GetContent(JSContext* aCx, mozilla::ErrorResult& aError);
JSObject* Get_content(JSContext* aCx, mozilla::ErrorResult& aError)
void GetContent(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
mozilla::ErrorResult& aError);
void Get_content(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetval,
mozilla::ErrorResult& aError)
{
if (mDoc) {
mDoc->WarnOnceAbout(nsIDocument::eWindow_Content);
}
return GetContent(aCx, aError);
GetContent(aCx, aRetval, aError);
}
// ChromeWindow bits. Do NOT call these unless your window is in

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

@ -5642,7 +5642,9 @@ def getRetvalDeclarationForType(returnType, descriptorProvider,
return CGGeneric("JS::Value"), None, None, None
return CGGeneric("JS::Rooted<JS::Value>"), "ptr", None, "cx"
if returnType.isObject() or returnType.isSpiderMonkeyInterface():
return CGGeneric("JSObject*"), None, None, None
if isMember:
return CGGeneric("JSObject*"), None, None, None
return CGGeneric("JS::Rooted<JSObject*>"), "ptr", None, "cx"
if returnType.isSequence():
nullable = returnType.nullable()
if nullable:
@ -11588,13 +11590,19 @@ class CGNativeMember(ClassMethod):
return "void", "", "aRetVal.set(${declName});\n"
if type.isObject():
return "JSObject*", "nullptr", "return ${declName};\n"
if isMember:
# No need for a third element in the isMember case
return "JSObject*", None, None
return "void", "", "aRetVal.set(${declName});\n"
if type.isSpiderMonkeyInterface():
if isMember:
# No need for a third element in the isMember case
return "JSObject*", None, None
if type.nullable():
returnCode = "return ${declName}.IsNull() ? nullptr : ${declName}.Value().Obj();\n"
returnCode = "${declName}.IsNull() ? nullptr : ${declName}.Value().Obj();\n"
else:
returnCode = "return ${declName}.Obj();\n"
return "JSObject*", "nullptr", returnCode
returnCode = "${declName}.Obj();\n"
return "void", "", "aRetVal.set(%s);\n" % returnCode
if type.isSequence():
# If we want to handle sequence-of-sequences return values, we're
# going to need to fix example codegen to not produce nsTArray<void>
@ -11686,6 +11694,8 @@ class CGNativeMember(ClassMethod):
"aRetVal"))
elif returnType.isAny():
args.append(Argument("JS::MutableHandle<JS::Value>", "aRetVal"))
elif returnType.isObject() or returnType.isSpiderMonkeyInterface():
args.append(Argument("JS::MutableHandle<JSObject*>", "aRetVal"))
# And the ErrorResult
if 'infallible' not in self.extendedAttrs:
@ -13566,7 +13576,8 @@ class CGEventGetter(CGNativeMember):
if (${memberName}) {
JS::ExposeObjectToActiveJS(${memberName});
}
return ${memberName};
aRetVal.set(${memberName});
return;
""",
memberName=memberName)
if type.isAny():

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

@ -450,7 +450,7 @@ public:
void PassMozMapOfNullableArrayBuffers(const MozMap<Nullable<ArrayBuffer> >&);
void PassVariadicTypedArray(const Sequence<Float32Array>&);
void PassVariadicNullableTypedArray(const Sequence<Nullable<Float32Array> >&);
JSObject* ReceiveUint8Array(JSContext*);
void ReceiveUint8Array(JSContext*, JS::MutableHandle<JSObject*>);
// DOMString types
void PassString(const nsAString&);
@ -539,8 +539,8 @@ public:
void PassOptionalNullableSequenceOfNullableSequenceOfObject(JSContext*, const Optional<Nullable<Sequence<Nullable<Sequence<JSObject*> > > > >&);
void PassOptionalNullableSequenceOfNullableSequenceOfNullableObject(JSContext*, const Optional<Nullable<Sequence<Nullable<Sequence<JSObject*> > > > >&);
void PassMozMapOfObject(JSContext*, const MozMap<JSObject*>&);
JSObject* ReceiveObject(JSContext*);
JSObject* ReceiveNullableObject(JSContext*);
void ReceiveObject(JSContext*, JS::MutableHandle<JSObject*>);
void ReceiveNullableObject(JSContext*, JS::MutableHandle<JSObject*>);
// Union types
void PassUnion(JSContext*, const ObjectOrLong& arg);

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

@ -7,6 +7,7 @@
#ifndef mozilla_dom_RsaKeyAlgorithm_h
#define mozilla_dom_RsaKeyAlgorithm_h
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/KeyAlgorithm.h"
#include "js/TypeDecls.h"
@ -35,10 +36,16 @@ public:
return mModulusLength;
}
JSObject* PublicExponent(JSContext* cx) const
void GetPublicExponent(JSContext* cx, JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aError) const
{
TypedArrayCreator<Uint8Array> creator(mPublicExponent);
return creator.Create(cx);
JSObject* retval = creator.Create(cx);
if (!retval) {
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
} else {
aRetval.set(retval);
}
}
virtual bool WriteStructuredClone(JSStructuredCloneWriter* aWriter) const MOZ_OVERRIDE;

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

@ -34,11 +34,12 @@ TextEncoder::Init(const nsAString& aEncoding, ErrorResult& aRv)
mEncoder = EncodingUtils::EncoderForEncoding(mEncoding);
}
JSObject*
void
TextEncoder::Encode(JSContext* aCx,
JS::Handle<JSObject*> aObj,
const nsAString& aString,
const bool aStream,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv)
{
// Run the steps of the encoding algorithm.
@ -48,7 +49,7 @@ TextEncoder::Encode(JSContext* aCx,
nsresult rv = mEncoder->GetMaxLength(data, srcLen, &maxLen);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
return;
}
// Need a fallible allocator because the caller may be a content
// and the content can specify the length of the string.
@ -56,7 +57,7 @@ TextEncoder::Encode(JSContext* aCx,
nsAutoArrayPtr<char> buf(new (fallible) char[maxLen + 1]);
if (!buf) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
return;
}
int32_t dstLen = maxLen;
@ -80,14 +81,14 @@ TextEncoder::Encode(JSContext* aCx,
reinterpret_cast<uint8_t*>(buf.get()));
if (!outView) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
return;
}
}
if (NS_FAILED(rv)) {
aRv.Throw(rv);
}
return outView;
aRetval.set(outView);
}
void

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

@ -46,12 +46,13 @@ public:
return TextEncoderBinding::Wrap(aCx, this, aTookOwnership);
}
JSObject* Encode(JSContext* aCx,
JS::Handle<JSObject*> aObj,
const nsAString& aString,
const TextEncodeOptions& aOptions,
ErrorResult& aRv) {
return TextEncoder::Encode(aCx, aObj, aString, aOptions.mStream, aRv);
void Encode(JSContext* aCx,
JS::Handle<JSObject*> aObj,
const nsAString& aString,
const TextEncodeOptions& aOptions,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv) {
TextEncoder::Encode(aCx, aObj, aString, aOptions.mStream, aRetval, aRv);
}
protected:
@ -85,13 +86,15 @@ public:
* If the streaming option is false, then the encoding
* algorithm state will get reset. If set to true then
* the previous encoding is reused/continued.
* @return JSObject* The Uint8Array wrapped in a JS object.
* @return JSObject* The Uint8Array wrapped in a JS object. Returned via
* the aRetval out param.
*/
JSObject* Encode(JSContext* aCx,
JS::Handle<JSObject*> aObj,
const nsAString& aString,
const bool aStream,
ErrorResult& aRv);
void Encode(JSContext* aCx,
JS::Handle<JSObject*> aObj,
const nsAString& aString,
const bool aStream,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv);
private:
nsCString mEncoding;

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

@ -60,46 +60,28 @@ public:
return mTnf;
}
JSObject* GetType(JSContext* cx) const
void GetType(JSContext* cx, JS::MutableHandle<JSObject*> retval) const
{
if (mType) {
return GetTypeObject();
} else {
return nullptr;
JS::ExposeObjectToActiveJS(mType);
}
}
JSObject* GetTypeObject() const
{
JS::ExposeObjectToActiveJS(mType);
return mType;
retval.set(mType);
}
JSObject* GetId(JSContext* cx) const
void GetId(JSContext* cx, JS::MutableHandle<JSObject*> retval) const
{
if (mId) {
return GetIdObject();
} else {
return nullptr;
JS::ExposeObjectToActiveJS(mId);
}
}
JSObject* GetIdObject() const
{
JS::ExposeObjectToActiveJS(mId);
return mId;
retval.set(mId);
}
JSObject* GetPayload(JSContext* cx) const
void GetPayload(JSContext* cx, JS::MutableHandle<JSObject*> retval) const
{
if (mPayload) {
return GetPayloadObject();
} else {
return nullptr;
JS::ExposeObjectToActiveJS(mPayload);
}
}
JSObject* GetPayloadObject() const
{
JS::ExposeObjectToActiveJS(mPayload);
return mPayload;
retval.set(mPayload);
}
private:

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

@ -32,6 +32,7 @@ interface HmacKeyAlgorithm : KeyAlgorithm {
[NoInterfaceObject]
interface RsaKeyAlgorithm : KeyAlgorithm {
readonly attribute unsigned long modulusLength;
[Throws]
readonly attribute BigInteger publicExponent;
};

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

@ -47,23 +47,24 @@ FileReaderSync::WrapObject(JSContext* aCx)
return FileReaderSyncBinding_workers::Wrap(aCx, this);
}
JSObject*
void
FileReaderSync::ReadAsArrayBuffer(JSContext* aCx,
JS::Handle<JSObject*> aScopeObj,
JS::Handle<JSObject*> aBlob,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv)
{
nsIDOMBlob* blob = file::GetDOMBlobFromJSObject(aBlob);
if (!blob) {
aRv.Throw(NS_ERROR_INVALID_ARG);
return nullptr;
return;
}
uint64_t blobSize;
nsresult rv = blob->GetSize(&blobSize);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
return;
}
JS::Rooted<JSObject*> jsArrayBuffer(aCx, JS_NewArrayBuffer(aCx, blobSize));
@ -71,32 +72,32 @@ FileReaderSync::ReadAsArrayBuffer(JSContext* aCx,
// XXXkhuey we need a way to indicate to the bindings that the call failed
// but there's already a pending exception that we should not clobber.
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
return;
}
uint32_t bufferLength = JS_GetArrayBufferByteLength(jsArrayBuffer);
uint8_t* arrayBuffer = JS_GetStableArrayBufferData(aCx, jsArrayBuffer);
if (!arrayBuffer) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
return;
}
nsCOMPtr<nsIInputStream> stream;
rv = blob->GetInternalStream(getter_AddRefs(stream));
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
return;
}
uint32_t numRead;
rv = stream->Read((char*)arrayBuffer, bufferLength, &numRead);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
return;
}
NS_ASSERTION(numRead == bufferLength, "failed to read data");
return jsArrayBuffer;
aRetval.set(jsArrayBuffer);
}
void

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

@ -42,9 +42,10 @@ public:
JSObject* WrapObject(JSContext* aCx);
JSObject* ReadAsArrayBuffer(JSContext* aCx, JS::Handle<JSObject*> aScopeObj,
JS::Handle<JSObject*> aBlob,
ErrorResult& aRv);
void ReadAsArrayBuffer(JSContext* aCx, JS::Handle<JSObject*> aScopeObj,
JS::Handle<JSObject*> aBlob,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv);
void ReadAsBinaryString(JS::Handle<JSObject*> aBlob, nsAString& aResult,
ErrorResult& aRv);
void ReadAsText(JS::Handle<JSObject*> aBlob,