Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(396)

Unified Diff: Source/bindings/v8/custom/V8BlobCustom.cpp

Issue 57483002: Implement File constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed most feedback. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/v8/V8BindingMacros.h ('k') | Source/bindings/v8/custom/V8BlobCustomHelpers.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/custom/V8BlobCustom.cpp
diff --git a/Source/bindings/v8/custom/V8BlobCustom.cpp b/Source/bindings/v8/custom/V8BlobCustom.cpp
index 96ba6135987e8bb9f0019d176ef202a3b0c34047..be506f80374096ebac08dd0b60c987fc79110ba9 100644
--- a/Source/bindings/v8/custom/V8BlobCustom.cpp
+++ b/Source/bindings/v8/custom/V8BlobCustom.cpp
@@ -31,14 +31,8 @@
#include "config.h"
#include "V8Blob.h"
-#include "bindings/v8/Dictionary.h"
-#include "bindings/v8/ExceptionMessages.h"
-#include "bindings/v8/V8Binding.h"
-#include "bindings/v8/V8Utilities.h"
-#include "bindings/v8/custom/V8ArrayBufferCustom.h"
-#include "bindings/v8/custom/V8ArrayBufferViewCustom.h"
+#include "bindings/v8/custom/V8BlobCustomHelpers.h"
#include "core/fileapi/BlobBuilder.h"
-#include "wtf/RefPtr.h"
namespace WebCore {
@@ -46,7 +40,7 @@ void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
if (!info.Length()) {
RefPtr<Blob> blob = Blob::create();
- info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate()));
+ v8SetReturnValue(info, blob.release());
return;
}
@@ -61,63 +55,25 @@ void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
}
}
- String type;
- String endings = "transparent";
-
+ String contentType;
+ String endings = "transparent"; // default if no BlobPropertyBag is passed
if (info.Length() > 1) {
if (!info[1]->IsObject()) {
throwTypeError(ExceptionMessages::failedToConstruct("Blob", "The 2nd argument is not of type Object."), info.GetIsolate());
return;
}
- V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsolate()));
-
- V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings));
- if (containsEndings) {
- if (endings != "transparent" && endings != "native") {
- throwTypeError(ExceptionMessages::failedToConstruct("Blob", "The 2nd argument's \"endings\" property must be either \"transparent\" or \"native\"."), info.GetIsolate());
- return;
- }
- }
-
- V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type));
- UNUSED_PARAM(containsType);
- if (!type.containsOnlyASCII()) {
- throwError(v8SyntaxError, ExceptionMessages::failedToConstruct("Blob", "The 2nd argument's \"type\" property must consist of ASCII characters."), info.GetIsolate());
+ if (!V8BlobCustomHelpers::processBlobPropertyBag(info[1], "Blob", contentType, endings, info.GetIsolate()))
return;
- }
- type = type.lower();
}
- ASSERT(endings == "transparent" || endings == "native");
-
BlobBuilder blobBuilder;
v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]);
- for (uint32_t i = 0; i < length; ++i) {
- v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, info.GetIsolate()));
- if (item.IsEmpty())
- return;
-
- if (V8ArrayBuffer::hasInstance(item, info.GetIsolate(), worldType(info.GetIsolate()))) {
- ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Object>::Cast(item));
- ASSERT(arrayBuffer);
- blobBuilder.append(arrayBuffer);
- } else if (V8ArrayBufferView::hasInstance(item, info.GetIsolate(), worldType(info.GetIsolate()))) {
- ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::Handle<v8::Object>::Cast(item));
- ASSERT(arrayBufferView);
- blobBuilder.append(arrayBufferView);
- } else if (V8Blob::hasInstance(item, info.GetIsolate(), worldType(info.GetIsolate()))) {
- Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item));
- ASSERT(blob);
- blobBuilder.append(blob);
- } else {
- V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue, item);
- blobBuilder.append(stringValue, endings);
- }
- }
+ if (!V8BlobCustomHelpers::processBlobParts(blobParts, length, endings, blobBuilder, info.GetIsolate()))
+ return;
- RefPtr<Blob> blob = blobBuilder.getBlob(type);
- info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate()));
+ RefPtr<Blob> blob = blobBuilder.createBlob(contentType);
+ v8SetReturnValue(info, blob.release());
}
} // namespace WebCore
« no previous file with comments | « Source/bindings/v8/V8BindingMacros.h ('k') | Source/bindings/v8/custom/V8BlobCustomHelpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698