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

Unified Diff: Source/bindings/v8/custom/V8BlobCustomHelpers.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/custom/V8BlobCustomHelpers.h ('k') | Source/bindings/v8/custom/V8FileCustom.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/custom/V8BlobCustomHelpers.cpp
diff --git a/Source/bindings/v8/custom/V8BlobCustom.cpp b/Source/bindings/v8/custom/V8BlobCustomHelpers.cpp
similarity index 51%
copy from Source/bindings/v8/custom/V8BlobCustom.cpp
copy to Source/bindings/v8/custom/V8BlobCustomHelpers.cpp
index 96ba6135987e8bb9f0019d176ef202a3b0c34047..ee359371b85b659787f80360eee7cc35104bd2fd 100644
--- a/Source/bindings/v8/custom/V8BlobCustom.cpp
+++ b/Source/bindings/v8/custom/V8BlobCustomHelpers.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -29,95 +29,74 @@
*/
#include "config.h"
-#include "V8Blob.h"
+#include "V8BlobCustomHelpers.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 "core/fileapi/BlobBuilder.h"
-#include "wtf/RefPtr.h"
namespace WebCore {
-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()));
- return;
- }
-
- uint32_t length = 0;
- if (info[0]->IsArray()) {
- length = v8::Local<v8::Array>::Cast(info[0])->Length();
- } else {
- const int sequenceArgumentIndex = 0;
- if (toV8Sequence(info[sequenceArgumentIndex], length, info.GetIsolate()).IsEmpty()) {
- throwTypeError(ExceptionMessages::failedToConstruct("Blob", ExceptionMessages::notAnArrayTypeArgumentOrValue(sequenceArgumentIndex + 1)), info.GetIsolate());
- return;
- }
- }
-
- String type;
- String endings = "transparent";
+namespace V8BlobCustomHelpers {
- if (info.Length() > 1) {
- if (!info[1]->IsObject()) {
- throwTypeError(ExceptionMessages::failedToConstruct("Blob", "The 2nd argument is not of type Object."), info.GetIsolate());
- return;
- }
+bool processBlobPropertyBag(v8::Local<v8::Value> propertyBag, const char* blobClassName, String& contentType, String& endings, v8::Isolate* isolate)
+{
+ ASSERT(endings == "transparent");
- V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsolate()));
+ V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate), false);
- 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_RETURN(bool, containsEndings, dictionary.get("endings", endings), false);
+ if (containsEndings) {
+ if (endings != "transparent" && endings != "native") {
+ throwTypeError(ExceptionMessages::failedToConstruct(blobClassName, "The \"endings\" property must be either \"transparent\" or \"native\"."), isolate);
+ return false;
}
+ }
- 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());
- return;
+ V8TRYCATCH_RETURN(bool, containsType, dictionary.get("type", contentType), false);
+ if (containsType) {
+ if (!contentType.containsOnlyASCII()) {
+ throwError(v8SyntaxError, ExceptionMessages::failedToConstruct(blobClassName, "The \"type\" property must consist of ASCII characters."), isolate);
+ return false;
}
- type = type.lower();
+ contentType = contentType.lower();
}
+ return true;
+}
+bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength, const String& endings, BlobBuilder& blobBuilder, v8::Isolate* isolate)
+{
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()));
+ for (uint32_t i = 0; i < blobPartsLength; ++i) {
+ v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, isolate));
if (item.IsEmpty())
- return;
+ return false;
- if (V8ArrayBuffer::hasInstance(item, info.GetIsolate(), worldType(info.GetIsolate()))) {
+ if (V8ArrayBuffer::hasInstance(item, isolate, worldType(isolate))) {
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()))) {
+ } else if (V8ArrayBufferView::hasInstance(item, isolate, worldType(isolate))) {
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()))) {
+ } else if (V8Blob::hasInstance(item, isolate, worldType(isolate))) {
Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item));
ASSERT(blob);
blobBuilder.append(blob);
} else {
- V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue, item);
+ V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, item, false);
blobBuilder.append(stringValue, endings);
}
}
-
- RefPtr<Blob> blob = blobBuilder.getBlob(type);
- info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate()));
+ return true;
}
+} // namespace V8BlobCustomHelpers
+
} // namespace WebCore
« no previous file with comments | « Source/bindings/v8/custom/V8BlobCustomHelpers.h ('k') | Source/bindings/v8/custom/V8FileCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698