This source file includes following definitions.
- m_hasLastModified
- setLastModified
- setDefaultLastModified
- parseBlobPropertyBag
- processBlobParts
#include "config.h"
#include "V8BlobCustomHelpers.h"
#include "V8Blob.h"
#include "bindings/v8/Dictionary.h"
#include "bindings/v8/ExceptionState.h"
#include "bindings/v8/V8Binding.h"
#include "bindings/v8/custom/V8ArrayBufferCustom.h"
#include "bindings/v8/custom/V8ArrayBufferViewCustom.h"
#include "wtf/DateMath.h"
namespace WebCore {
namespace V8BlobCustomHelpers {
ParsedProperties::ParsedProperties(bool hasFileProperties)
: m_normalizeLineEndingsToNative(false)
, m_hasFileProperties(hasFileProperties)
#ifndef NDEBUG
, m_hasLastModified(false)
#endif
{
}
void ParsedProperties::setLastModified(double lastModified)
{
ASSERT(m_hasFileProperties);
ASSERT(!m_hasLastModified);
m_lastModified = lastModified;
#ifndef NDEBUG
m_hasLastModified = true;
#endif
}
void ParsedProperties::setDefaultLastModified()
{
setLastModified(currentTime());
}
bool ParsedProperties::parseBlobPropertyBag(v8::Local<v8::Value> propertyBag, const char* blobClassName, ExceptionState& exceptionState, v8::Isolate* isolate)
{
V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate), false);
String endings;
V8TRYCATCH_RETURN(bool, containsEndings, dictionary.get("endings", endings), false);
if (containsEndings) {
if (endings != "transparent" && endings != "native") {
exceptionState.throwTypeError("The 'endings' property must be either 'transparent' or 'native'.");
return false;
}
if (endings == "native")
m_normalizeLineEndingsToNative = true;
}
V8TRYCATCH_RETURN(bool, containsType, dictionary.get("type", m_contentType), false);
if (containsType) {
if (!m_contentType.containsOnlyASCII()) {
exceptionState.throwDOMException(SyntaxError, "The 'type' property must consist of ASCII characters.");
return false;
}
m_contentType = m_contentType.lower();
}
if (!m_hasFileProperties)
return true;
v8::Local<v8::Value> lastModified;
V8TRYCATCH_RETURN(bool, containsLastModified, dictionary.get("lastModified", lastModified), false);
if (containsLastModified) {
V8TRYCATCH_RETURN(long long, lastModifiedInt, toInt64(lastModified), false);
setLastModified(static_cast<double>(lastModifiedInt) / msPerSecond);
} else {
setDefaultLastModified();
}
return true;
}
bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength, bool normalizeLineEndingsToNative, BlobData& blobData, v8::Isolate* isolate)
{
for (uint32_t i = 0; i < blobPartsLength; ++i) {
v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(isolate, i));
if (item.IsEmpty())
return false;
if (V8ArrayBuffer::hasInstance(item, isolate)) {
ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Object>::Cast(item));
ASSERT(arrayBuffer);
blobData.appendArrayBuffer(arrayBuffer);
} else if (V8ArrayBufferView::hasInstance(item, isolate)) {
ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::Handle<v8::Object>::Cast(item));
ASSERT(arrayBufferView);
blobData.appendArrayBufferView(arrayBufferView);
} else if (V8Blob::hasInstance(item, isolate)) {
Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item));
ASSERT(blob);
blob->appendTo(blobData);
} else {
V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringValue, item, false);
blobData.appendText(stringValue, normalizeLineEndingsToNative);
}
}
return true;
}
}
}