| 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 23 matching lines...) Expand all Loading... |
| 34 #include "bindings/v8/Dictionary.h" | 34 #include "bindings/v8/Dictionary.h" |
| 35 #include "bindings/v8/V8Binding.h" | 35 #include "bindings/v8/V8Binding.h" |
| 36 #include "bindings/v8/V8Utilities.h" | 36 #include "bindings/v8/V8Utilities.h" |
| 37 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | 37 #include "bindings/v8/custom/V8ArrayBufferCustom.h" |
| 38 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" | 38 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" |
| 39 #include "core/fileapi/BlobBuilder.h" | 39 #include "core/fileapi/BlobBuilder.h" |
| 40 #include "wtf/RefPtr.h" | 40 #include "wtf/RefPtr.h" |
| 41 | 41 |
| 42 namespace WebCore { | 42 namespace WebCore { |
| 43 | 43 |
| 44 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& args) | 44 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 45 { | 45 { |
| 46 if (!args.Length()) { | 46 if (!info.Length()) { |
| 47 RefPtr<Blob> blob = Blob::create(); | 47 RefPtr<Blob> blob = Blob::create(); |
| 48 args.GetReturnValue().Set(toV8(blob.get(), args.Holder(), args.GetIsolat
e())); | 48 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat
e())); |
| 49 return; | 49 return; |
| 50 } | 50 } |
| 51 | 51 |
| 52 v8::Local<v8::Value> firstArg = args[0]; | 52 v8::Local<v8::Value> firstArg = info[0]; |
| 53 if (!firstArg->IsArray()) { | 53 if (!firstArg->IsArray()) { |
| 54 throwTypeError("First argument of the constructor is not of type Array",
args.GetIsolate()); | 54 throwTypeError("First argument of the constructor is not of type Array",
info.GetIsolate()); |
| 55 return; | 55 return; |
| 56 } | 56 } |
| 57 | 57 |
| 58 String type; | 58 String type; |
| 59 String endings = "transparent"; | 59 String endings = "transparent"; |
| 60 | 60 |
| 61 if (args.Length() > 1) { | 61 if (info.Length() > 1) { |
| 62 if (!args[1]->IsObject()) { | 62 if (!info[1]->IsObject()) { |
| 63 throwTypeError("Second argument of the constructor is not of type Ob
ject", args.GetIsolate()); | 63 throwTypeError("Second argument of the constructor is not of type Ob
ject", info.GetIsolate()); |
| 64 return; | 64 return; |
| 65 } | 65 } |
| 66 | 66 |
| 67 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(args[1], args.GetIsol
ate())); | 67 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsol
ate())); |
| 68 | 68 |
| 69 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings
)); | 69 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings
)); |
| 70 if (containsEndings) { | 70 if (containsEndings) { |
| 71 if (endings != "transparent" && endings != "native") { | 71 if (endings != "transparent" && endings != "native") { |
| 72 throwTypeError("The endings property must be either \"transparen
t\" or \"native\"", args.GetIsolate()); | 72 throwTypeError("The endings property must be either \"transparen
t\" or \"native\"", info.GetIsolate()); |
| 73 return; | 73 return; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); | 77 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); |
| 78 UNUSED_PARAM(containsType); | 78 UNUSED_PARAM(containsType); |
| 79 if (!type.containsOnlyASCII()) { | 79 if (!type.containsOnlyASCII()) { |
| 80 throwError(v8SyntaxError, "type must consist of ASCII characters", a
rgs.GetIsolate()); | 80 throwError(v8SyntaxError, "type must consist of ASCII characters", i
nfo.GetIsolate()); |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 type = type.lower(); | 83 type = type.lower(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 ASSERT(endings == "transparent" || endings == "native"); | 86 ASSERT(endings == "transparent" || endings == "native"); |
| 87 | 87 |
| 88 BlobBuilder blobBuilder; | 88 BlobBuilder blobBuilder; |
| 89 | 89 |
| 90 V8TRYCATCH_VOID(v8::Local<v8::Array>, blobParts, v8::Local<v8::Array>::Cast(
firstArg)); | 90 V8TRYCATCH_VOID(v8::Local<v8::Array>, blobParts, v8::Local<v8::Array>::Cast(
firstArg)); |
| 91 uint32_t length = blobParts->Length(); | 91 uint32_t length = blobParts->Length(); |
| 92 | 92 |
| 93 for (uint32_t i = 0; i < length; ++i) { | 93 for (uint32_t i = 0; i < length; ++i) { |
| 94 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, args.GetIs
olate())); | 94 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, info.GetIs
olate())); |
| 95 ASSERT(!item.IsEmpty()); | 95 ASSERT(!item.IsEmpty()); |
| 96 if (V8ArrayBuffer::HasInstance(item, args.GetIsolate(), worldType(args.G
etIsolate()))) { | 96 if (V8ArrayBuffer::HasInstance(item, info.GetIsolate(), worldType(info.G
etIsolate()))) { |
| 97 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Ob
ject>::Cast(item)); | 97 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Ob
ject>::Cast(item)); |
| 98 ASSERT(arrayBuffer); | 98 ASSERT(arrayBuffer); |
| 99 blobBuilder.append(arrayBuffer); | 99 blobBuilder.append(arrayBuffer); |
| 100 } else if (V8ArrayBufferView::HasInstance(item, args.GetIsolate(), world
Type(args.GetIsolate()))) { | 100 } else if (V8ArrayBufferView::HasInstance(item, info.GetIsolate(), world
Type(info.GetIsolate()))) { |
| 101 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::H
andle<v8::Object>::Cast(item)); | 101 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::H
andle<v8::Object>::Cast(item)); |
| 102 ASSERT(arrayBufferView); | 102 ASSERT(arrayBufferView); |
| 103 blobBuilder.append(arrayBufferView); | 103 blobBuilder.append(arrayBufferView); |
| 104 } else if (V8Blob::HasInstance(item, args.GetIsolate(), worldType(args.G
etIsolate()))) { | 104 } else if (V8Blob::HasInstance(item, info.GetIsolate(), worldType(info.G
etIsolate()))) { |
| 105 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); | 105 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); |
| 106 ASSERT(blob); | 106 ASSERT(blob); |
| 107 blobBuilder.append(blob); | 107 blobBuilder.append(blob); |
| 108 } else { | 108 } else { |
| 109 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue
, item); | 109 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue
, item); |
| 110 blobBuilder.append(stringValue, endings); | 110 blobBuilder.append(stringValue, endings); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 RefPtr<Blob> blob = blobBuilder.getBlob(type); | 114 RefPtr<Blob> blob = blobBuilder.getBlob(type); |
| 115 args.GetReturnValue().Set(toV8(blob.get(), args.Holder(), args.GetIsolate())
); | 115 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate())
); |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace WebCore | 118 } // namespace WebCore |
| OLD | NEW |