OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 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 |
(...skipping 15 matching lines...) Expand all Loading... |
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 "bindings/core/v8/V8File.h" | 32 #include "bindings/core/v8/V8File.h" |
33 | 33 |
34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
35 #include "bindings/core/v8/custom/V8BlobCustomHelpers.h" | 35 #include "bindings/core/v8/custom/V8BlobCustomHelpers.h" |
36 #include "platform/RuntimeEnabledFeatures.h" | |
37 | 36 |
38 namespace blink { | 37 namespace blink { |
39 | 38 |
40 void V8File::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) | 39 void V8File::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
41 { | 40 { |
42 ExceptionState exceptionState(ExceptionState::ConstructionContext, "File", i
nfo.Holder(), info.GetIsolate()); | 41 ExceptionState exceptionState(ExceptionState::ConstructionContext, "File", i
nfo.Holder(), info.GetIsolate()); |
43 | 42 |
44 if (!RuntimeEnabledFeatures::fileConstructorEnabled()) { | |
45 exceptionState.throwTypeError("Illegal constructor"); | |
46 exceptionState.throwIfNeeded(); | |
47 return; | |
48 } | |
49 | |
50 if (info.Length() < 2) { | 43 if (info.Length() < 2) { |
51 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i
nfo.Length())); | 44 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i
nfo.Length())); |
52 exceptionState.throwIfNeeded(); | 45 exceptionState.throwIfNeeded(); |
53 return; | 46 return; |
54 } | 47 } |
55 | 48 |
56 // FIXME: handle sequences based on ES6 @@iterator, see http://crbug.com/393
866 | 49 // FIXME: handle sequences based on ES6 @@iterator, see http://crbug.com/393
866 |
57 if (!info[0]->IsArray()) { | 50 if (!info[0]->IsArray()) { |
58 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect
Type(1, "Array")); | 51 exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrect
Type(1, "Array")); |
59 exceptionState.throwIfNeeded(); | 52 exceptionState.throwIfNeeded(); |
(...skipping 22 matching lines...) Expand all Loading... |
82 blobData->setContentType(properties.contentType()); | 75 blobData->setContentType(properties.contentType()); |
83 v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]); | 76 v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]); |
84 if (!V8BlobCustomHelpers::processBlobParts(blobParts, properties.normalizeLi
neEndingsToNative(), *blobData, info.GetIsolate())) | 77 if (!V8BlobCustomHelpers::processBlobParts(blobParts, properties.normalizeLi
neEndingsToNative(), *blobData, info.GetIsolate())) |
85 return; | 78 return; |
86 | 79 |
87 long long fileSize = blobData->length(); | 80 long long fileSize = blobData->length(); |
88 RefPtrWillBeRawPtr<File> file = File::create(fileName, properties.lastModifi
ed(), BlobDataHandle::create(blobData.release(), fileSize)); | 81 RefPtrWillBeRawPtr<File> file = File::create(fileName, properties.lastModifi
ed(), BlobDataHandle::create(blobData.release(), fileSize)); |
89 v8SetReturnValue(info, file.release()); | 82 v8SetReturnValue(info, file.release()); |
90 } | 83 } |
91 | 84 |
92 void V8File::lastModifiedDateAttributeGetterCustom(const v8::PropertyCallbackInf
o<v8::Value>& info) | |
93 { | |
94 // The auto-generated getters return null when the method in the underlying | |
95 // implementation returns NaN. The File API says we should return the | |
96 // current time when the last modification time is unknown. | |
97 // Section 7.2 of the File API spec. http://dev.w3.org/2006/webapi/FileAPI/ | |
98 | |
99 File* file = V8File::toNative(info.Holder()); | |
100 double lastModified = file->lastModifiedDate(); | |
101 if (!isValidFileTime(lastModified)) | |
102 lastModified = currentTimeMS(); | |
103 | |
104 // lastModifiedDate returns a Date instance. | |
105 // http://www.w3.org/TR/FileAPI/#file-attrs | |
106 v8SetReturnValue(info, v8::Date::New(info.GetIsolate(), lastModified)); | |
107 } | |
108 | |
109 void V8File::lastModifiedAttributeGetterCustom(const v8::PropertyCallbackInfo<v8
::Value>& info) | |
110 { | |
111 File* file = V8File::toNative(info.Holder()); | |
112 double lastModified = file->lastModifiedDate(); | |
113 if (!isValidFileTime(lastModified)) | |
114 lastModified = currentTimeMS(); | |
115 | |
116 // lastModified returns a number, not a Date instance. | |
117 // http://dev.w3.org/2006/webapi/FileAPI/#file-attrs | |
118 v8SetReturnValue(info, floor(lastModified)); | |
119 } | |
120 | |
121 } // namespace blink | 85 } // namespace blink |
OLD | NEW |