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

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: Factored common code out of Blob and File custom constructors. 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
Index: Source/bindings/v8/custom/V8BlobCustom.cpp
diff --git a/Source/bindings/v8/custom/V8BlobCustom.cpp b/Source/bindings/v8/custom/V8BlobCustom.cpp
index d514a4eff6a71eb5d36f0cdd090baecd2215bb7e..8504874de3fc5e8245c270c62d7a8635588d19f0 100644
--- a/Source/bindings/v8/custom/V8BlobCustom.cpp
+++ b/Source/bindings/v8/custom/V8BlobCustom.cpp
@@ -31,11 +31,7 @@
#include "config.h"
#include "V8Blob.h"
-#include "bindings/v8/Dictionary.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"
@@ -49,69 +45,30 @@ void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
return;
}
- v8::Local<v8::Value> firstArg = info[0];
- if (!firstArg->IsArray()) {
+ // FIXME: handle WebIDL sequences, see http://crbug.com/314755
+ if (!info[0]->IsArray()) {
throwTypeError("First argument of the constructor is not of type Array", info.GetIsolate());
return;
}
- String type;
+ String contentType;
String endings = "transparent";
-
if (info.Length() > 1) {
if (!info[1]->IsObject()) {
throwTypeError("Second argument of the constructor 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("The 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, "type must consist of ASCII characters", info.GetIsolate());
+ if (!V8BlobCustomHelpers::processBlobPropertyBag(info[1], info.GetIsolate(), contentType, endings))
return;
- }
- type = type.lower();
}
-
ASSERT(endings == "transparent" || endings == "native");
BlobBuilder blobBuilder;
+ if (!V8BlobCustomHelpers::processBlobParts(info[0], info.GetIsolate(), endings, blobBuilder))
+ return;
- V8TRYCATCH_VOID(v8::Local<v8::Array>, blobParts, v8::Local<v8::Array>::Cast(firstArg));
- uint32_t length = blobParts->Length();
-
- for (uint32_t i = 0; i < length; ++i) {
- v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, info.GetIsolate()));
- ASSERT(!item.IsEmpty());
- 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);
- }
- }
-
- RefPtr<Blob> blob = blobBuilder.getBlob(type);
+ RefPtr<Blob> blob = blobBuilder.createBlob(contentType);
info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate()));
}

Powered by Google App Engine
This is Rietveld 408576698