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 53% |
copy from Source/bindings/v8/custom/V8BlobCustom.cpp |
copy to Source/bindings/v8/custom/V8BlobCustomHelpers.cpp |
index d514a4eff6a71eb5d36f0cdd090baecd2215bb7e..1022540b6d2ad7a27809567769f13ff2db2d7cc2 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,90 +29,71 @@ |
*/ |
#include "config.h" |
-#include "V8Blob.h" |
+#include "V8BlobCustomHelpers.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 "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; |
- } |
- |
- v8::Local<v8::Value> firstArg = info[0]; |
- if (!firstArg->IsArray()) { |
- throwTypeError("First argument of the constructor is not of type Array", info.GetIsolate()); |
- return; |
- } |
- |
- String type; |
- 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; |
- } |
+namespace V8BlobCustomHelpers { |
- V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsolate())); |
+bool processBlobPropertyBag(v8::Local<v8::Value> propertyBag, v8::Isolate* isolate, String& contentType, String& endings) |
+{ |
+ V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate), false); |
- 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_RETURN(bool, containsEndings, dictionary.get("endings", endings), false); |
+ if (containsEndings) { |
+ if (endings != "transparent" && endings != "native") { |
+ throwTypeError("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, "type must consist of ASCII characters", info.GetIsolate()); |
- return; |
+ V8TRYCATCH_RETURN(bool, containsType, dictionary.get("type", contentType), false); |
+ if (containsType) { |
+ if (!contentType.containsOnlyASCII()) { |
+ throwError(v8SyntaxError, "type must consist of ASCII characters", isolate); |
+ return false; |
} |
- type = type.lower(); |
+ contentType = contentType.lower(); |
} |
+ return true; |
+} |
- ASSERT(endings == "transparent" || endings == "native"); |
- |
- BlobBuilder blobBuilder; |
- |
- V8TRYCATCH_VOID(v8::Local<v8::Array>, blobParts, v8::Local<v8::Array>::Cast(firstArg)); |
- uint32_t length = blobParts->Length(); |
+bool processBlobParts(v8::Local<v8::Value> blobParts, v8::Isolate* isolate, const String& endings, BlobBuilder& blobBuilder) |
+{ |
+ V8TRYCATCH_RETURN(v8::Local<v8::Array>, partsArray, v8::Local<v8::Array>::Cast(blobParts), false); |
+ uint32_t length = partsArray->Length(); |
for (uint32_t i = 0; i < length; ++i) { |
- v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, info.GetIsolate())); |
+ v8::Local<v8::Value> item = partsArray->Get(v8::Uint32::New(i, isolate)); |
ASSERT(!item.IsEmpty()); |
- 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 |