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

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

Issue 74213009: File constructor understands lastModified. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed feedback. 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
« no previous file with comments | « Source/bindings/v8/custom/V8BlobCustomHelpers.cpp ('k') | Source/core/fileapi/File.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } else { 55 } else {
56 const int sequenceArgumentIndex = 0; 56 const int sequenceArgumentIndex = 0;
57 if (toV8Sequence(info[sequenceArgumentIndex], length, info.GetIsolate()) .IsEmpty()) { 57 if (toV8Sequence(info[sequenceArgumentIndex], length, info.GetIsolate()) .IsEmpty()) {
58 throwTypeError(ExceptionMessages::failedToConstruct("File", Exceptio nMessages::notAnArrayTypeArgumentOrValue(sequenceArgumentIndex + 1)), info.GetIs olate()); 58 throwTypeError(ExceptionMessages::failedToConstruct("File", Exceptio nMessages::notAnArrayTypeArgumentOrValue(sequenceArgumentIndex + 1)), info.GetIs olate());
59 return; 59 return;
60 } 60 }
61 } 61 }
62 62
63 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, fileName, info[1]); 63 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, fileName, info[1]);
64 64
65 String contentType; 65 V8BlobCustomHelpers::ParsedProperties properties(true);
66 String endings = "transparent"; // default if no BlobPropertyBag is passed
67 if (info.Length() > 2) { 66 if (info.Length() > 2) {
68 if (!info[2]->IsObject()) { 67 if (!info[2]->IsObject()) {
69 throwTypeError(ExceptionMessages::failedToConstruct("File", "The 3rd argument is not of type Object."), info.GetIsolate()); 68 throwTypeError(ExceptionMessages::failedToConstruct("File", "The 3rd argument is not of type Object."), info.GetIsolate());
70 return; 69 return;
71 } 70 }
72 71
73 if (!V8BlobCustomHelpers::processBlobPropertyBag(info[2], "File", conten tType, endings, info.GetIsolate())) 72 if (!properties.parseBlobPropertyBag(info[2], "File", info.GetIsolate()) )
74 return; 73 return;
74 } else {
75 properties.setDefaultLastModified();
75 } 76 }
76 77
77 BlobBuilder blobBuilder; 78 BlobBuilder blobBuilder;
78 v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]); 79 v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]);
79 if (!V8BlobCustomHelpers::processBlobParts(blobParts, length, endings, blobB uilder, info.GetIsolate())) 80 if (!V8BlobCustomHelpers::processBlobParts(blobParts, length, properties.end ings(), blobBuilder, info.GetIsolate()))
80 return; 81 return;
81 82
82 RefPtr<File> file = blobBuilder.createFile(contentType, fileName, currentTim e()); 83 RefPtr<File> file = blobBuilder.createFile(properties.contentType(), fileNam e, properties.lastModified());
83 v8SetReturnValue(info, file.release()); 84 v8SetReturnValue(info, file.release());
84 } 85 }
85 86
87 void V8File::lastModifiedDateAttributeGetterCustom(const v8::PropertyCallbackInf o<v8::Value>& info)
88 {
89 // The auto-generated getters return null when the method in the underlying
90 // implementation returns NaN. The File API says we should return the
91 // current time when the last modification time is unknown.
92 // Section 7.2 of the File API spec. http://dev.w3.org/2006/webapi/FileAPI/
93
94 File* file = V8File::toNative(info.Holder());
95 double lastModified = file->lastModifiedDate();
96 if (!isValidFileTime(lastModified))
97 lastModified = currentTimeMS();
98 v8SetReturnValue(info, v8::Date::New(lastModified));
99 }
100
101 void V8File::lastModifiedAttributeGetterCustom(const v8::PropertyCallbackInfo<v8 ::Value>& info)
102 {
103 File* file = V8File::toNative(info.Holder());
104 double lastModified = file->lastModifiedDate();
105 if (!isValidFileTime(lastModified))
106 lastModified = currentTimeMS();
107 v8SetReturnValue(info, floor(lastModified));
108 }
109
86 } // namespace WebCore 110 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/custom/V8BlobCustomHelpers.cpp ('k') | Source/core/fileapi/File.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698