forked from mirrors/gecko-dev
		
	Bug 1897871 - Implement PushMessageData .bytes() method. r=saschanaz,webidl
				
					
				
			Implements https://github.com/w3c/push-api/pull/370 Differential Revision: https://phabricator.services.mozilla.com/D212319
This commit is contained in:
		
							parent
							
								
									2645d76146
								
							
						
					
					
						commit
						6518590f3c
					
				
					 5 changed files with 16 additions and 0 deletions
				
			
		|  | @ -130,6 +130,7 @@ http://creativecommons.org/licenses/publicdomain/ | ||||||
|     ); |     ); | ||||||
|     isDeeply(new Uint8Array(message.data.arrayBuffer), typedArray, |     isDeeply(new Uint8Array(message.data.arrayBuffer), typedArray, | ||||||
|       "Wrong array buffer message data"); |       "Wrong array buffer message data"); | ||||||
|  |     isDeeply(message.data.bytes, typedArray, "Wrong bytes message data"); | ||||||
| 
 | 
 | ||||||
|     message = await waitForMessage( |     message = await waitForMessage( | ||||||
|       pushSubscription, |       pushSubscription, | ||||||
|  |  | ||||||
|  | @ -73,6 +73,7 @@ function handlePush(event) { | ||||||
|         arrayBuffer: event.data.arrayBuffer(), |         arrayBuffer: event.data.arrayBuffer(), | ||||||
|         json: getJSON(event.data), |         json: getJSON(event.data), | ||||||
|         blob: event.data.blob(), |         blob: event.data.blob(), | ||||||
|  |         bytes: event.data.bytes(), | ||||||
|       }; |       }; | ||||||
|     } |     } | ||||||
|     broadcast(event, message); |     broadcast(event, message); | ||||||
|  |  | ||||||
|  | @ -1100,6 +1100,16 @@ already_AddRefed<mozilla::dom::Blob> PushMessageData::Blob(ErrorResult& aRv) { | ||||||
|   return nullptr; |   return nullptr; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void PushMessageData::Bytes(JSContext* cx, JS::MutableHandle<JSObject*> aRetval, | ||||||
|  |                             ErrorResult& aRv) { | ||||||
|  |   uint8_t* data = GetContentsCopy(); | ||||||
|  |   if (data) { | ||||||
|  |     UniquePtr<uint8_t[], JS::FreePolicy> dataPtr(data); | ||||||
|  |     BodyUtil::ConsumeBytes(cx, aRetval, mBytes.Length(), std::move(dataPtr), | ||||||
|  |                            aRv); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| nsresult PushMessageData::EnsureDecodedText() { | nsresult PushMessageData::EnsureDecodedText() { | ||||||
|   if (mBytes.IsEmpty() || !mDecodedText.IsEmpty()) { |   if (mBytes.IsEmpty() || !mDecodedText.IsEmpty()) { | ||||||
|     return NS_OK; |     return NS_OK; | ||||||
|  |  | ||||||
|  | @ -215,6 +215,8 @@ class PushMessageData final : public nsISupports, public nsWrapperCache { | ||||||
|   void ArrayBuffer(JSContext* cx, JS::MutableHandle<JSObject*> aRetval, |   void ArrayBuffer(JSContext* cx, JS::MutableHandle<JSObject*> aRetval, | ||||||
|                    ErrorResult& aRv); |                    ErrorResult& aRv); | ||||||
|   already_AddRefed<mozilla::dom::Blob> Blob(ErrorResult& aRv); |   already_AddRefed<mozilla::dom::Blob> Blob(ErrorResult& aRv); | ||||||
|  |   void Bytes(JSContext* cx, JS::MutableHandle<JSObject*> aRetval, | ||||||
|  |              ErrorResult& aRv); | ||||||
| 
 | 
 | ||||||
|   PushMessageData(nsIGlobalObject* aOwner, nsTArray<uint8_t>&& aBytes); |   PushMessageData(nsIGlobalObject* aOwner, nsTArray<uint8_t>&& aBytes); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -16,6 +16,8 @@ interface PushMessageData | ||||||
|     [Throws] |     [Throws] | ||||||
|     Blob        blob(); |     Blob        blob(); | ||||||
|     [Throws] |     [Throws] | ||||||
|  |     Uint8Array  bytes(); | ||||||
|  |     [Throws] | ||||||
|     any         json(); |     any         json(); | ||||||
|     USVString   text(); |     USVString   text(); | ||||||
| }; | }; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Tom Schuster
						Tom Schuster