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

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

Issue 74213009: File constructor understands lastModified. (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) 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 25 matching lines...) Expand all
36 #include "bindings/v8/V8Binding.h" 36 #include "bindings/v8/V8Binding.h"
37 #include "bindings/v8/V8Utilities.h" 37 #include "bindings/v8/V8Utilities.h"
38 #include "bindings/v8/custom/V8ArrayBufferCustom.h" 38 #include "bindings/v8/custom/V8ArrayBufferCustom.h"
39 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" 39 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h"
40 #include "core/fileapi/BlobBuilder.h" 40 #include "core/fileapi/BlobBuilder.h"
41 41
42 namespace WebCore { 42 namespace WebCore {
43 43
44 namespace V8BlobCustomHelpers { 44 namespace V8BlobCustomHelpers {
45 45
46 bool processBlobPropertyBag(v8::Local<v8::Value> propertyBag, const char* blobCl assName, String& contentType, String& endings, v8::Isolate* isolate) 46 ParsedProperties::ParsedProperties(bool hasFileProperties)
47 : endings("transparent")
48 , hasFileProperties(hasFileProperties)
49 , m_hasLastModifiedDate(false)
47 { 50 {
48 ASSERT(endings == "transparent"); 51 }
52
53 double ParsedProperties::lastModifiedDate()
54 {
55 ASSERT(this->hasFileProperties);
56 if (!m_hasLastModifiedDate) {
57 m_lastModifiedDate = currentTime();
58 m_hasLastModifiedDate = true;
59 }
60 return m_lastModifiedDate;
61 }
62
63 void ParsedProperties::setLastModifiedDate(double lastModifiedDate)
64 {
65 ASSERT(this->hasFileProperties);
66 m_lastModifiedDate = lastModifiedDate;
67 m_hasLastModifiedDate = true;
68 }
69
70 bool processBlobPropertyBag(v8::Local<v8::Value> propertyBag, const char* blobCl assName, ParsedProperties& parsedProperties, v8::Isolate* isolate)
71 {
72 ASSERT(parsedProperties.endings == "transparent");
73 String& endings = parsedProperties.endings;
49 74
50 V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate), false); 75 V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate), false);
51 76
52 V8TRYCATCH_RETURN(bool, containsEndings, dictionary.get("endings", endings), false); 77 V8TRYCATCH_RETURN(bool, containsEndings, dictionary.get("endings", endings), false);
53 if (containsEndings) { 78 if (containsEndings) {
54 if (endings != "transparent" && endings != "native") { 79 if (endings != "transparent" && endings != "native") {
55 throwTypeError(ExceptionMessages::failedToConstruct(blobClassName, " The \"endings\" property must be either \"transparent\" or \"native\"."), isolat e); 80 throwTypeError(ExceptionMessages::failedToConstruct(blobClassName, " The \"endings\" property must be either \"transparent\" or \"native\"."), isolat e);
56 return false; 81 return false;
57 } 82 }
58 } 83 }
59 84
85 String& contentType = parsedProperties.contentType;
60 V8TRYCATCH_RETURN(bool, containsType, dictionary.get("type", contentType), f alse); 86 V8TRYCATCH_RETURN(bool, containsType, dictionary.get("type", contentType), f alse);
61 if (containsType) { 87 if (containsType) {
62 if (!contentType.containsOnlyASCII()) { 88 if (!contentType.containsOnlyASCII()) {
63 throwError(v8SyntaxError, ExceptionMessages::failedToConstruct(blobC lassName, "The \"type\" property must consist of ASCII characters."), isolate); 89 throwError(v8SyntaxError, ExceptionMessages::failedToConstruct(blobC lassName, "The \"type\" property must consist of ASCII characters."), isolate);
64 return false; 90 return false;
65 } 91 }
66 contentType = contentType.lower(); 92 contentType = contentType.lower();
67 } 93 }
94
95 if (!parsedProperties.hasFileProperties)
96 return true;
97
98 v8::Local<v8::Value> lastModifiedDate;
99 V8TRYCATCH_RETURN(bool, containsLastModifiedDate, dictionary.get("lastModifi edDate", lastModifiedDate), false);
100 if (containsLastModifiedDate) {
101 if (!lastModifiedDate->IsDate() && !lastModifiedDate->IsNumber()) {
sof 2013/11/17 07:42:37 From spec standpoint, Number appears an extension;
pwnall-personal 2013/11/17 09:01:23 I was confused by step 3 sub-step 3 in the File co
sof 2013/11/17 12:53:40 By the time you come to those steps, value convers
pwnall-personal 2013/11/17 16:02:08 Thank you for explaining! I removed the support fo
102 throwError(v8SyntaxError, ExceptionMessages::failedToConstruct(blobC lassName, "The \"lastModifiedDate\" property must be a Date instance."), isolate );
sof 2013/11/17 12:53:40 If the value conversion fails, a TypeError should
pwnall-personal 2013/11/17 16:02:08 Done. Thank you for catching this!
103 return false;
104 }
105 parsedProperties.setLastModifiedDate(static_cast<double>(lastModifiedDat e->NumberValue()) / 1000.0); // ms to seconds
106 }
sof 2013/11/17 07:42:37 If you call setLastModifiedDate(currentTime()) her
pwnall-personal 2013/11/17 09:01:23 Sadly, that is not the case. This method is only c
sof 2013/11/17 12:53:40 Hmm, you're right - not quite as easy as it first
pwnall-personal 2013/11/17 16:02:08 I got rid of the boolean in release builds, which
107
68 return true; 108 return true;
69 } 109 }
70 110
71 bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength, const String& endings, BlobBuilder& blobBuilder, v8::Isolate* isolate) 111 bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength, const String& endings, BlobBuilder& blobBuilder, v8::Isolate* isolate)
72 { 112 {
73 ASSERT(endings == "transparent" || endings == "native"); 113 ASSERT(endings == "transparent" || endings == "native");
74 114
75 for (uint32_t i = 0; i < blobPartsLength; ++i) { 115 for (uint32_t i = 0; i < blobPartsLength; ++i) {
76 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, isolate)); 116 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, isolate));
77 if (item.IsEmpty()) 117 if (item.IsEmpty())
(...skipping 15 matching lines...) Expand all
93 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal ue, item, false); 133 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal ue, item, false);
94 blobBuilder.append(stringValue, endings); 134 blobBuilder.append(stringValue, endings);
95 } 135 }
96 } 136 }
97 return true; 137 return true;
98 } 138 }
99 139
100 } // namespace V8BlobCustomHelpers 140 } // namespace V8BlobCustomHelpers
101 141
102 } // namespace WebCore 142 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/custom/V8BlobCustomHelpers.h ('k') | Source/bindings/v8/custom/V8FileCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698