Chromium Code Reviews| 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 50% |
| copy from Source/bindings/v8/custom/V8BlobCustom.cpp |
| copy to Source/bindings/v8/custom/V8BlobCustomHelpers.cpp |
| index 96ba6135987e8bb9f0019d176ef202a3b0c34047..7bea21870088eff92cd702ba8b12f3243b34a04d 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,70 @@ |
| */ |
| #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) |
| +namespace V8BlobCustomHelpers { |
| + |
| +bool processBlobPropertyBag(v8::Local<v8::Value> propertyBag, v8::Isolate* isolate, const char* blobClassName, String& contentType, String& endings) |
| { |
| - if (!info.Length()) { |
| - RefPtr<Blob> blob = Blob::create(); |
| - info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate())); |
| - return; |
| - } |
| + V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate), false); |
| - 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; |
| + 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); |
|
haraken
2013/11/15 08:40:05
Nit: You could use '...' and avoid \".
pwnall-personal
2013/11/15 10:28:53
Hm... AFAIK, single quotes mean char in C++. I tri
haraken
2013/11/15 10:39:12
Sorry, you're right. Ignore my comment :)
|
| + return false; |
| } |
| } |
| - String type; |
| - String endings = "transparent"; |
| - |
| - 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_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); |
|
haraken
2013/11/15 08:40:05
Ditto.
pwnall-personal
2013/11/15 10:28:53
Same issue as above. Sorry for being dense :(
|
| + 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; |
| - } |
| - type = type.lower(); |
| + contentType = contentType.lower(); |
| } |
| + return true; |
| +} |
| - 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())); |
| +bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength, v8::Isolate* isolate, const String& endings, BlobBuilder& blobBuilder) |
| +{ |
| + 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 |