Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: Source/bindings/v8/custom/V8FileCustom.cpp

Issue 57483002: Implement File constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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()) {
48 throwTypeError("Illegal constructor", info.GetIsolate());
49 return;
50 }
51
52 if (info.Length() < 2) {
53 throwTypeError("Constructor requires at least two arguments", info.GetIs olate());
47 RefPtr<Blob> blob = Blob::create(); 54 RefPtr<Blob> blob = Blob::create();
Inactive 2013/11/04 14:13:11 Why are we creating a blob in the error case?
pwnall-personal 2013/11/04 17:16:25 Done. (Fixed.) This was an unfortunate mix betwee
48 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat e())); 55 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat e()));
49 return; 56 return;
50 } 57 }
51 58
52 v8::Local<v8::Value> firstArg = info[0]; 59 v8::Local<v8::Value> firstArg = info[0];
53 if (!firstArg->IsArray()) { 60 if (!firstArg->IsArray()) {
Inactive 2013/11/04 14:13:11 Actually, the spec says it is a sequence, not an a
pwnall-personal 2013/11/04 17:16:25 Good point! I got this from V8BlobCustom, so the
54 throwTypeError("First argument of the constructor is not of type Array", info.GetIsolate()); 61 throwTypeError("First argument of the constructor is not of type Array", info.GetIsolate());
55 return; 62 return;
56 } 63 }
57 64
65 v8::Local<v8::Value> secondArg = info[1];
66 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, fileName, secondArg );
67
58 String type; 68 String type;
59 String endings = "transparent"; 69 String endings = "transparent";
60 70
61 if (info.Length() > 1) { 71 if (info.Length() > 2) {
62 if (!info[1]->IsObject()) { 72 if (!info[2]->IsObject()) {
63 throwTypeError("Second argument of the constructor is not of type Ob ject", info.GetIsolate()); 73 throwTypeError("Third argument of the constructor is not of type Obj ect", info.GetIsolate());
64 return; 74 return;
65 } 75 }
66 76
67 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsol ate())); 77 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[2], info.GetIsol ate()));
68 78
69 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings )); 79 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings ));
70 if (containsEndings) { 80 if (containsEndings) {
71 if (endings != "transparent" && endings != "native") { 81 if (endings != "transparent" && endings != "native") {
72 throwTypeError("The endings property must be either \"transparen t\" or \"native\"", info.GetIsolate()); 82 throwTypeError("The endings property must be either \"transparen t\" or \"native\"", info.GetIsolate());
73 return; 83 return;
74 } 84 }
75 } 85 }
76 86
77 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); 87 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type));
(...skipping 26 matching lines...) Expand all
104 } else if (V8Blob::HasInstance(item, info.GetIsolate(), worldType(info.G etIsolate()))) { 114 } else if (V8Blob::HasInstance(item, info.GetIsolate(), worldType(info.G etIsolate()))) {
105 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); 115 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item));
106 ASSERT(blob); 116 ASSERT(blob);
107 blobBuilder.append(blob); 117 blobBuilder.append(blob);
108 } else { 118 } else {
109 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue , item); 119 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue , item);
110 blobBuilder.append(stringValue, endings); 120 blobBuilder.append(stringValue, endings);
111 } 121 }
112 } 122 }
113 123
114 RefPtr<Blob> blob = blobBuilder.getBlob(type); 124 RefPtr<File> file = blobBuilder.getFile(type, fileName, currentTime());
115 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate()) ); 125 info.GetReturnValue().Set(toV8(file.get(), info.Holder(), info.GetIsolate()) );
116 } 126 }
117 127
118 } // namespace WebCore 128 } // namespace WebCore
129
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698