OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 "V8File.h" |
33 | 33 |
34 #include "RuntimeEnabledFeatures.h" | |
34 #include "bindings/v8/Dictionary.h" | 35 #include "bindings/v8/Dictionary.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 V8File::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
45 { | 46 { |
46 if (!info.Length()) { | 47 if (!RuntimeEnabledFeatures::fileConstructorEnabled()) { |
47 RefPtr<Blob> blob = Blob::create(); | 48 throwTypeError("Illegal constructor", info.GetIsolate()); |
48 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat e())); | |
49 return; | 49 return; |
50 } | 50 } |
51 | 51 |
52 if (info.Length() < 2) { | |
53 throwTypeError("Constructor requires at least two arguments", info.GetIs olate()); | |
54 return; | |
55 } | |
56 | |
52 v8::Local<v8::Value> firstArg = info[0]; | 57 v8::Local<v8::Value> firstArg = info[0]; |
53 if (!firstArg->IsArray()) { | 58 if (!firstArg->IsArray()) { |
Inactive
2013/11/04 18:33:53
Filing a bug and adding a FIXME comment here and i
pwnall-personal
2013/11/04 19:20:53
Done.
Bug: http://crbug.com/314755
| |
54 throwTypeError("First argument of the constructor is not of type Array", info.GetIsolate()); | 59 throwTypeError("First argument of the constructor is not of type Array", info.GetIsolate()); |
55 return; | 60 return; |
56 } | 61 } |
57 | 62 |
63 v8::Local<v8::Value> secondArg = info[1]; | |
64 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, fileName, secondArg ); | |
65 | |
58 String type; | 66 String type; |
59 String endings = "transparent"; | 67 String endings = "transparent"; |
60 | 68 |
61 if (info.Length() > 1) { | 69 if (info.Length() > 2) { |
62 if (!info[1]->IsObject()) { | 70 if (!info[2]->IsObject()) { |
63 throwTypeError("Second argument of the constructor is not of type Ob ject", info.GetIsolate()); | 71 throwTypeError("Third argument of the constructor is not of type Obj ect", info.GetIsolate()); |
64 return; | 72 return; |
65 } | 73 } |
66 | 74 |
67 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsol ate())); | 75 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[2], info.GetIsol ate())); |
68 | 76 |
69 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings )); | 77 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings )); |
70 if (containsEndings) { | 78 if (containsEndings) { |
71 if (endings != "transparent" && endings != "native") { | 79 if (endings != "transparent" && endings != "native") { |
72 throwTypeError("The endings property must be either \"transparen t\" or \"native\"", info.GetIsolate()); | 80 throwTypeError("The endings property must be either \"transparen t\" or \"native\"", info.GetIsolate()); |
73 return; | 81 return; |
74 } | 82 } |
75 } | 83 } |
76 | 84 |
77 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); | 85 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); |
(...skipping 26 matching lines...) Expand all Loading... | |
104 } else if (V8Blob::HasInstance(item, info.GetIsolate(), worldType(info.G etIsolate()))) { | 112 } else if (V8Blob::HasInstance(item, info.GetIsolate(), worldType(info.G etIsolate()))) { |
105 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); | 113 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); |
106 ASSERT(blob); | 114 ASSERT(blob); |
107 blobBuilder.append(blob); | 115 blobBuilder.append(blob); |
108 } else { | 116 } else { |
109 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue , item); | 117 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue , item); |
110 blobBuilder.append(stringValue, endings); | 118 blobBuilder.append(stringValue, endings); |
111 } | 119 } |
112 } | 120 } |
113 | 121 |
114 RefPtr<Blob> blob = blobBuilder.getBlob(type); | 122 RefPtr<File> file = blobBuilder.getFile(type, fileName, currentTime()); |
115 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate()) ); | 123 info.GetReturnValue().Set(toV8(file.get(), info.Holder(), info.GetIsolate()) ); |
116 } | 124 } |
117 | 125 |
118 } // namespace WebCore | 126 } // namespace WebCore |
127 | |
OLD | NEW |