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

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

Issue 57483002: Implement File constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed nits. 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 namespace WebCore { 42 namespace WebCore {
43 43
44 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) 44 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
45 { 45 {
46 if (!info.Length()) { 46 if (!info.Length()) {
47 RefPtr<Blob> blob = Blob::create(); 47 RefPtr<Blob> blob = Blob::create();
48 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat e())); 48 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat e()));
49 return; 49 return;
50 } 50 }
51 51
52 v8::Local<v8::Value> firstArg = info[0]; 52 // FIXME: handle WebIDL sequences, see http://crbug.com/314755
53 if (!firstArg->IsArray()) { 53 if (!info[0]->IsArray()) {
54 throwTypeError("First argument of the constructor is not of type Array", info.GetIsolate()); 54 throwTypeError("First argument of the constructor is not of type Array", info.GetIsolate());
55 return; 55 return;
56 } 56 }
57 57
58 String type; 58 String type;
59 String endings = "transparent"; 59 String endings = "transparent";
60 60
61 if (info.Length() > 1) { 61 if (info.Length() > 1) {
62 if (!info[1]->IsObject()) { 62 if (!info[1]->IsObject()) {
63 throwTypeError("Second argument of the constructor is not of type Ob ject", info.GetIsolate()); 63 throwTypeError("Second argument of the constructor is not of type Ob ject", info.GetIsolate());
(...skipping 16 matching lines...) Expand all
80 throwError(v8SyntaxError, "type must consist of ASCII characters", i nfo.GetIsolate()); 80 throwError(v8SyntaxError, "type must consist of ASCII characters", i nfo.GetIsolate());
81 return; 81 return;
82 } 82 }
83 type = type.lower(); 83 type = type.lower();
84 } 84 }
85 85
86 ASSERT(endings == "transparent" || endings == "native"); 86 ASSERT(endings == "transparent" || endings == "native");
87 87
88 BlobBuilder blobBuilder; 88 BlobBuilder blobBuilder;
89 89
90 V8TRYCATCH_VOID(v8::Local<v8::Array>, blobParts, v8::Local<v8::Array>::Cast( firstArg)); 90 V8TRYCATCH_VOID(v8::Local<v8::Array>, blobParts, v8::Local<v8::Array>::Cast( info[0]));
91 uint32_t length = blobParts->Length(); 91 uint32_t length = blobParts->Length();
92 92
93 for (uint32_t i = 0; i < length; ++i) { 93 for (uint32_t i = 0; i < length; ++i) {
94 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, info.GetIs olate())); 94 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, info.GetIs olate()));
95 ASSERT(!item.IsEmpty()); 95 ASSERT(!item.IsEmpty());
96 if (V8ArrayBuffer::HasInstance(item, info.GetIsolate(), worldType(info.G etIsolate()))) { 96 if (V8ArrayBuffer::HasInstance(item, info.GetIsolate(), worldType(info.G etIsolate()))) {
97 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Ob ject>::Cast(item)); 97 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Ob ject>::Cast(item));
98 ASSERT(arrayBuffer); 98 ASSERT(arrayBuffer);
99 blobBuilder.append(arrayBuffer); 99 blobBuilder.append(arrayBuffer);
100 } else if (V8ArrayBufferView::HasInstance(item, info.GetIsolate(), world Type(info.GetIsolate()))) { 100 } else if (V8ArrayBufferView::HasInstance(item, info.GetIsolate(), world Type(info.GetIsolate()))) {
101 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::H andle<v8::Object>::Cast(item)); 101 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::H andle<v8::Object>::Cast(item));
102 ASSERT(arrayBufferView); 102 ASSERT(arrayBufferView);
103 blobBuilder.append(arrayBufferView); 103 blobBuilder.append(arrayBufferView);
104 } else if (V8Blob::HasInstance(item, info.GetIsolate(), worldType(info.G etIsolate()))) { 104 } else if (V8Blob::HasInstance(item, info.GetIsolate(), worldType(info.G etIsolate()))) {
105 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); 105 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item));
106 ASSERT(blob); 106 ASSERT(blob);
107 blobBuilder.append(blob); 107 blobBuilder.append(blob);
108 } else { 108 } else {
109 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue , item); 109 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue , item);
110 blobBuilder.append(stringValue, endings); 110 blobBuilder.append(stringValue, endings);
111 } 111 }
112 } 112 }
113 113
114 RefPtr<Blob> blob = blobBuilder.getBlob(type); 114 RefPtr<Blob> blob = blobBuilder.createBlob(type);
115 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate()) ); 115 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate()) );
116 } 116 }
117 117
118 } // namespace WebCore 118 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698