Commit 08f457e9 authored by sigbjornf@opera.com's avatar sigbjornf@opera.com

Remove custom getters for File.lastModified{Date}

No particular need for these to be custom, so turned into File accessors
instead.

Also drop a runtime feature check for FileConstructor; it is now stable.

R=haraken
BUG=

Review URL: https://codereview.chromium.org/458953002

git-svn-id: svn://svn.chromium.org/blink/trunk@179944 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 157a6e0b
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "bindings/core/v8/ExceptionState.h" #include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/custom/V8BlobCustomHelpers.h" #include "bindings/core/v8/custom/V8BlobCustomHelpers.h"
#include "platform/RuntimeEnabledFeatures.h"
namespace blink { namespace blink {
...@@ -41,12 +40,6 @@ void V8File::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) ...@@ -41,12 +40,6 @@ void V8File::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{ {
ExceptionState exceptionState(ExceptionState::ConstructionContext, "File", info.Holder(), info.GetIsolate()); ExceptionState exceptionState(ExceptionState::ConstructionContext, "File", info.Holder(), info.GetIsolate());
if (!RuntimeEnabledFeatures::fileConstructorEnabled()) {
exceptionState.throwTypeError("Illegal constructor");
exceptionState.throwIfNeeded();
return;
}
if (info.Length() < 2) { if (info.Length() < 2) {
exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, info.Length())); exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(2, info.Length()));
exceptionState.throwIfNeeded(); exceptionState.throwIfNeeded();
...@@ -89,33 +82,4 @@ void V8File::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) ...@@ -89,33 +82,4 @@ void V8File::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
v8SetReturnValue(info, file.release()); v8SetReturnValue(info, file.release());
} }
void V8File::lastModifiedDateAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info)
{
// The auto-generated getters return null when the method in the underlying
// implementation returns NaN. The File API says we should return the
// current time when the last modification time is unknown.
// Section 7.2 of the File API spec. http://dev.w3.org/2006/webapi/FileAPI/
File* file = V8File::toNative(info.Holder());
double lastModified = file->lastModifiedDate();
if (!isValidFileTime(lastModified))
lastModified = currentTimeMS();
// lastModifiedDate returns a Date instance.
// http://www.w3.org/TR/FileAPI/#file-attrs
v8SetReturnValue(info, v8::Date::New(info.GetIsolate(), lastModified));
}
void V8File::lastModifiedAttributeGetterCustom(const v8::PropertyCallbackInfo<v8::Value>& info)
{
File* file = V8File::toNative(info.Holder());
double lastModified = file->lastModifiedDate();
if (!isValidFileTime(lastModified))
lastModified = currentTimeMS();
// lastModified returns a number, not a Date instance.
// http://dev.w3.org/2006/webapi/FileAPI/#file-attrs
v8SetReturnValue(info, floor(lastModified));
}
} // namespace blink } // namespace blink
...@@ -165,7 +165,7 @@ File::File(const KURL& fileSystemURL, const FileMetadata& metadata) ...@@ -165,7 +165,7 @@ File::File(const KURL& fileSystemURL, const FileMetadata& metadata)
ScriptWrappable::init(this); ScriptWrappable::init(this);
} }
double File::lastModifiedDate() const double File::lastModifiedMS() const
{ {
if (hasValidSnapshotMetadata() && isValidFileTime(m_snapshotModificationTime)) if (hasValidSnapshotMetadata() && isValidFileTime(m_snapshotModificationTime))
return m_snapshotModificationTime * msPerSecond; return m_snapshotModificationTime * msPerSecond;
...@@ -177,6 +177,32 @@ double File::lastModifiedDate() const ...@@ -177,6 +177,32 @@ double File::lastModifiedDate() const
return currentTime() * msPerSecond; return currentTime() * msPerSecond;
} }
long long File::lastModified() const
{
double modifiedDate = lastModifiedMS();
// The getter should return the current time when the last modification time isn't known.
if (!isValidFileTime(modifiedDate))
modifiedDate = currentTimeMS();
// lastModified returns a number, not a Date instance,
// http://dev.w3.org/2006/webapi/FileAPI/#file-attrs
return floor(modifiedDate);
}
double File::lastModifiedDate() const
{
double modifiedDate = lastModifiedMS();
// The getter should return the current time when the last modification time isn't known.
if (!isValidFileTime(modifiedDate))
modifiedDate = currentTimeMS();
// lastModifiedDate returns a Date instance,
// http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate
return modifiedDate;
}
unsigned long long File::size() const unsigned long long File::size() const
{ {
if (hasValidSnapshotMetadata()) if (hasValidSnapshotMetadata())
......
...@@ -115,7 +115,12 @@ public: ...@@ -115,7 +115,12 @@ public:
const String& path() const { ASSERT(hasValidFilePath()); return m_path; } const String& path() const { ASSERT(hasValidFilePath()); return m_path; }
const String name() const { return m_name; } const String name() const { return m_name; }
// This returns the current date and time if the file's last modification date is not known (per spec: http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate). // Getter for the lastModified IDL attribute,
// http://dev.w3.org/2006/webapi/FileAPI/#file-attrs
long long lastModified() const;
// Getter for the lastModifiedDate IDL attribute,
// http://www.w3.org/TR/FileAPI/#dfn-lastModifiedDate
double lastModifiedDate() const; double lastModifiedDate() const;
UserVisibility userVisibility() const { return m_userVisibility; } UserVisibility userVisibility() const { return m_userVisibility; }
...@@ -139,6 +144,10 @@ private: ...@@ -139,6 +144,10 @@ private:
void invalidateSnapshotMetadata() { m_snapshotSize = -1; } void invalidateSnapshotMetadata() { m_snapshotSize = -1; }
// Returns File's last modified time (in MS since Epoch.)
// If the modification time isn't known, the current time is returned.
double lastModifiedMS() const;
#if ENABLE(ASSERT) #if ENABLE(ASSERT)
bool hasValidFileSystemURL() const { return hasBackingFile(); } bool hasValidFileSystemURL() const { return hasBackingFile(); }
// Instances not backed by a file must have an empty path set. // Instances not backed by a file must have an empty path set.
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
Exposed=(Window,Worker), Exposed=(Window,Worker),
] interface File : Blob { ] interface File : Blob {
readonly attribute DOMString name; readonly attribute DOMString name;
[Custom=Getter, MeasureAs=FileGetLastModifiedDate] readonly attribute Date lastModifiedDate; [MeasureAs=FileGetLastModifiedDate] readonly attribute Date lastModifiedDate;
[Custom=Getter, RuntimeEnabled=FileConstructor] readonly attribute long long lastModified; readonly attribute long long lastModified;
[MeasureAs=PrefixedFileRelativePath] readonly attribute DOMString webkitRelativePath; [MeasureAs=PrefixedFileRelativePath] readonly attribute DOMString webkitRelativePath;
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment