| 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 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 "V8File.h" | 32 #include "V8File.h" |
| 33 | 33 |
| 34 #include "RuntimeEnabledFeatures.h" | 34 #include "RuntimeEnabledFeatures.h" |
| 35 #include "bindings/v8/ExceptionState.h" |
| 35 #include "bindings/v8/custom/V8BlobCustomHelpers.h" | 36 #include "bindings/v8/custom/V8BlobCustomHelpers.h" |
| 36 #include "core/fileapi/BlobBuilder.h" | 37 #include "core/fileapi/BlobBuilder.h" |
| 37 | 38 |
| 38 namespace WebCore { | 39 namespace WebCore { |
| 39 | 40 |
| 40 void V8File::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) | 41 void V8File::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 41 { | 42 { |
| 43 ExceptionState exceptionState(ExceptionState::ConstructionContext, "File", i
nfo.Holder(), info.GetIsolate()); |
| 44 |
| 42 if (!RuntimeEnabledFeatures::fileConstructorEnabled()) { | 45 if (!RuntimeEnabledFeatures::fileConstructorEnabled()) { |
| 43 throwTypeError("Illegal constructor", info.GetIsolate()); | 46 exceptionState.throwTypeError("Illegal constructor"); |
| 47 exceptionState.throwIfNeeded(); |
| 44 return; | 48 return; |
| 45 } | 49 } |
| 46 | 50 |
| 47 if (info.Length() < 2) { | 51 if (info.Length() < 2) { |
| 48 throwTypeError("File constructor requires at least two arguments", info.
GetIsolate()); | 52 exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, i
nfo.Length())); |
| 53 exceptionState.throwIfNeeded(); |
| 49 return; | 54 return; |
| 50 } | 55 } |
| 51 | 56 |
| 52 uint32_t length = 0; | 57 uint32_t length = 0; |
| 53 if (info[0]->IsArray()) { | 58 if (info[0]->IsArray()) { |
| 54 length = v8::Local<v8::Array>::Cast(info[0])->Length(); | 59 length = v8::Local<v8::Array>::Cast(info[0])->Length(); |
| 55 } else { | 60 } else { |
| 56 const int sequenceArgumentIndex = 0; | 61 const int sequenceArgumentIndex = 0; |
| 57 if (toV8Sequence(info[sequenceArgumentIndex], length, info.GetIsolate())
.IsEmpty()) { | 62 if (toV8Sequence(info[sequenceArgumentIndex], length, info.GetIsolate())
.IsEmpty()) { |
| 58 throwTypeError(ExceptionMessages::failedToConstruct("File", Exceptio
nMessages::notAnArrayTypeArgumentOrValue(sequenceArgumentIndex + 1)), info.GetIs
olate()); | 63 exceptionState.throwTypeError(ExceptionMessages::notAnArrayTypeArgum
entOrValue(sequenceArgumentIndex + 1)); |
| 64 exceptionState.throwIfNeeded(); |
| 59 return; | 65 return; |
| 60 } | 66 } |
| 61 } | 67 } |
| 62 | 68 |
| 63 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, fileName, info[1]); | 69 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, fileName, info[1]); |
| 64 | 70 |
| 65 V8BlobCustomHelpers::ParsedProperties properties(true); | 71 V8BlobCustomHelpers::ParsedProperties properties(true); |
| 66 if (info.Length() > 2) { | 72 if (info.Length() > 2) { |
| 67 if (!info[2]->IsObject()) { | 73 if (!info[2]->IsObject()) { |
| 68 throwTypeError(ExceptionMessages::failedToConstruct("File", "The 3rd
argument is not of type Object."), info.GetIsolate()); | 74 exceptionState.throwTypeError("The 3rd argument is not of type Objec
t."); |
| 75 exceptionState.throwIfNeeded(); |
| 69 return; | 76 return; |
| 70 } | 77 } |
| 71 | 78 |
| 72 if (!properties.parseBlobPropertyBag(info[2], "File", info.GetIsolate())
) | 79 if (!properties.parseBlobPropertyBag(info[2], "File", exceptionState, in
fo.GetIsolate())) { |
| 80 exceptionState.throwIfNeeded(); |
| 73 return; | 81 return; |
| 82 } |
| 74 } else { | 83 } else { |
| 75 properties.setDefaultLastModified(); | 84 properties.setDefaultLastModified(); |
| 76 } | 85 } |
| 77 | 86 |
| 78 BlobBuilder blobBuilder; | 87 BlobBuilder blobBuilder; |
| 79 v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]); | 88 v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]); |
| 80 if (!V8BlobCustomHelpers::processBlobParts(blobParts, length, properties.end
ings(), blobBuilder, info.GetIsolate())) | 89 if (!V8BlobCustomHelpers::processBlobParts(blobParts, length, properties.end
ings(), blobBuilder, info.GetIsolate())) |
| 81 return; | 90 return; |
| 82 | 91 |
| 83 RefPtr<File> file = blobBuilder.createFile(properties.contentType(), fileNam
e, properties.lastModified()); | 92 RefPtr<File> file = blobBuilder.createFile(properties.contentType(), fileNam
e, properties.lastModified()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 107 double lastModified = file->lastModifiedDate(); | 116 double lastModified = file->lastModifiedDate(); |
| 108 if (!isValidFileTime(lastModified)) | 117 if (!isValidFileTime(lastModified)) |
| 109 lastModified = currentTimeMS(); | 118 lastModified = currentTimeMS(); |
| 110 | 119 |
| 111 // lastModified returns a number, not a Date instance. | 120 // lastModified returns a number, not a Date instance. |
| 112 // http://dev.w3.org/2006/webapi/FileAPI/#file-attrs | 121 // http://dev.w3.org/2006/webapi/FileAPI/#file-attrs |
| 113 v8SetReturnValue(info, floor(lastModified)); | 122 v8SetReturnValue(info, floor(lastModified)); |
| 114 } | 123 } |
| 115 | 124 |
| 116 } // namespace WebCore | 125 } // namespace WebCore |
| OLD | NEW |