| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "V8Blob.h" | 32 #include "V8Blob.h" |
| 33 | 33 |
| 34 #include "bindings/v8/Dictionary.h" | 34 #include "bindings/v8/Dictionary.h" |
| 35 #include "bindings/v8/ExceptionMessages.h" |
| 35 #include "bindings/v8/V8Binding.h" | 36 #include "bindings/v8/V8Binding.h" |
| 36 #include "bindings/v8/V8Utilities.h" | 37 #include "bindings/v8/V8Utilities.h" |
| 37 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | 38 #include "bindings/v8/custom/V8ArrayBufferCustom.h" |
| 38 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" | 39 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" |
| 39 #include "core/fileapi/BlobBuilder.h" | 40 #include "core/fileapi/BlobBuilder.h" |
| 40 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
| 41 | 42 |
| 42 namespace WebCore { | 43 namespace WebCore { |
| 43 | 44 |
| 44 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) | 45 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 45 { | 46 { |
| 46 if (!info.Length()) { | 47 if (!info.Length()) { |
| 47 RefPtr<Blob> blob = Blob::create(); | 48 RefPtr<Blob> blob = Blob::create(); |
| 48 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat
e())); | 49 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat
e())); |
| 49 return; | 50 return; |
| 50 } | 51 } |
| 51 | 52 |
| 52 uint32_t length = 0; | 53 uint32_t length = 0; |
| 53 if (info[0]->IsArray()) { | 54 if (info[0]->IsArray()) { |
| 54 length = v8::Local<v8::Array>::Cast(info[0])->Length(); | 55 length = v8::Local<v8::Array>::Cast(info[0])->Length(); |
| 55 } else { | 56 } else { |
| 56 bool notASequence = false; | 57 const int sequenceArgumentIndex = 0; |
| 57 toV8Sequence(info[0], length, notASequence, info.GetIsolate()); | 58 if (toV8Sequence(info[sequenceArgumentIndex], length, info.GetIsolate())
.IsEmpty()) { |
| 58 if (notASequence) { | 59 throwTypeError(ExceptionMessages::failedToConstruct("Blob", Exceptio
nMessages::notAnArrayTypeArgumentOrValue(sequenceArgumentIndex + 1)), info.GetIs
olate()); |
| 59 throwTypeError("First argument of the constructor is not of type Arr
ay", info.GetIsolate()); | |
| 60 return; | 60 return; |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 String type; | 64 String type; |
| 65 String endings = "transparent"; | 65 String endings = "transparent"; |
| 66 | 66 |
| 67 if (info.Length() > 1) { | 67 if (info.Length() > 1) { |
| 68 if (!info[1]->IsObject()) { | 68 if (!info[1]->IsObject()) { |
| 69 throwTypeError("Second argument of the constructor is not of type Ob
ject", info.GetIsolate()); | 69 throwTypeError(ExceptionMessages::failedToConstruct("Blob", "The 2nd
argument is not of type Object."), info.GetIsolate()); |
| 70 return; | 70 return; |
| 71 } | 71 } |
| 72 | 72 |
| 73 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsol
ate())); | 73 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsol
ate())); |
| 74 | 74 |
| 75 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings
)); | 75 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings
)); |
| 76 if (containsEndings) { | 76 if (containsEndings) { |
| 77 if (endings != "transparent" && endings != "native") { | 77 if (endings != "transparent" && endings != "native") { |
| 78 throwTypeError("The endings property must be either \"transparen
t\" or \"native\"", info.GetIsolate()); | 78 throwTypeError(ExceptionMessages::failedToConstruct("Blob", "The
2nd argument's \"endings\" property must be either \"transparent\" or \"native\
"."), info.GetIsolate()); |
| 79 return; | 79 return; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); | 83 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); |
| 84 UNUSED_PARAM(containsType); | 84 UNUSED_PARAM(containsType); |
| 85 if (!type.containsOnlyASCII()) { | 85 if (!type.containsOnlyASCII()) { |
| 86 throwError(v8SyntaxError, "type must consist of ASCII characters", i
nfo.GetIsolate()); | 86 throwError(v8SyntaxError, ExceptionMessages::failedToConstruct("Blob
", "The 2nd argument's \"type\" property must consist of ASCII characters."), in
fo.GetIsolate()); |
| 87 return; | 87 return; |
| 88 } | 88 } |
| 89 type = type.lower(); | 89 type = type.lower(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 ASSERT(endings == "transparent" || endings == "native"); | 92 ASSERT(endings == "transparent" || endings == "native"); |
| 93 | 93 |
| 94 BlobBuilder blobBuilder; | 94 BlobBuilder blobBuilder; |
| 95 v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]); | 95 v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]); |
| 96 for (uint32_t i = 0; i < length; ++i) { | 96 for (uint32_t i = 0; i < length; ++i) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 112 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue
, item); | 112 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue
, item); |
| 113 blobBuilder.append(stringValue, endings); | 113 blobBuilder.append(stringValue, endings); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 RefPtr<Blob> blob = blobBuilder.getBlob(type); | 117 RefPtr<Blob> blob = blobBuilder.getBlob(type); |
| 118 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate())
); | 118 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate())
); |
| 119 } | 119 } |
| 120 | 120 |
| 121 } // namespace WebCore | 121 } // namespace WebCore |
| OLD | NEW |