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

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

Issue 15877002: move constructors to new style callbacks (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 months 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 | Annotate | Revision Log
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 namespace WebCore { 44 namespace WebCore {
45 45
46 v8::Handle<v8::Object> wrap(Blob* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) 46 v8::Handle<v8::Object> wrap(Blob* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
47 { 47 {
48 ASSERT(impl); 48 ASSERT(impl);
49 if (impl->isFile()) 49 if (impl->isFile())
50 return wrap(toFile(impl), creationContext, isolate); 50 return wrap(toFile(impl), creationContext, isolate);
51 return V8Blob::createWrapper(impl, creationContext, isolate); 51 return V8Blob::createWrapper(impl, creationContext, isolate);
52 } 52 }
53 53
54 v8::Handle<v8::Value> V8Blob::constructorCustom(const v8::Arguments& args) 54 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
55 { 55 {
56 if (!args.Length()) { 56 if (!args.Length()) {
57 RefPtr<Blob> blob = Blob::create(); 57 RefPtr<Blob> blob = Blob::create();
58 return toV8(blob.get(), args.Holder(), args.GetIsolate()); 58 args.GetReturnValue().Set(toV8(blob.get(), args.Holder(), args.GetIsolat e()));
59 return;
59 } 60 }
60 61
61 v8::Local<v8::Value> firstArg = args[0]; 62 v8::Local<v8::Value> firstArg = args[0];
62 if (!firstArg->IsArray()) 63 if (!firstArg->IsArray()) {
63 return throwTypeError("First argument of the constructor is not of type Array", args.GetIsolate()); 64 throwTypeError("First argument of the constructor is not of type Array", args.GetIsolate());
65 return;
66 }
64 67
65 String type; 68 String type;
66 String endings = ASCIILiteral("transparent"); 69 String endings = ASCIILiteral("transparent");
67 70
68 if (args.Length() > 1) { 71 if (args.Length() > 1) {
69 if (!args[1]->IsObject()) 72 if (!args[1]->IsObject()) {
70 return throwTypeError("Second argument of the constructor is not of type Object", args.GetIsolate()); 73 throwTypeError("Second argument of the constructor is not of type Ob ject", args.GetIsolate());
71 74 return;
72 V8TRYCATCH(Dictionary, dictionary, Dictionary(args[1], args.GetIsolate() ));
73
74 V8TRYCATCH(bool, containsEndings, dictionary.get("endings", endings));
75 if (containsEndings) {
76 if (endings != "transparent" && endings != "native")
77 return throwTypeError("The endings property must be either \"tra nsparent\" or \"native\"", args.GetIsolate());
78 } 75 }
79 76
80 V8TRYCATCH(bool, containsType, dictionary.get("type", type)); 77 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(args[1], args.GetIsol ate()));
78
79 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings ));
80 if (containsEndings) {
81 if (endings != "transparent" && endings != "native") {
82 throwTypeError("The endings property must be either \"transparen t\" or \"native\"", args.GetIsolate());
83 return;
84 }
85 }
86
87 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type));
81 UNUSED_PARAM(containsType); 88 UNUSED_PARAM(containsType);
82 if (!type.containsOnlyASCII()) 89 if (!type.containsOnlyASCII()) {
83 return throwError(v8SyntaxError, "type must consist of ASCII charact ers", args.GetIsolate()); 90 throwError(v8SyntaxError, "type must consist of ASCII characters", a rgs.GetIsolate());
91 return;
92 }
84 type.makeLower(); 93 type.makeLower();
85 } 94 }
86 95
87 ASSERT(endings == "transparent" || endings == "native"); 96 ASSERT(endings == "transparent" || endings == "native");
88 97
89 BlobBuilder blobBuilder; 98 BlobBuilder blobBuilder;
90 99
91 V8TRYCATCH(v8::Local<v8::Array>, blobParts, v8::Local<v8::Array>::Cast(first Arg)); 100 V8TRYCATCH_VOID(v8::Local<v8::Array>, blobParts, v8::Local<v8::Array>::Cast( firstArg));
92 uint32_t length = blobParts->Length(); 101 uint32_t length = blobParts->Length();
93 102
94 for (uint32_t i = 0; i < length; ++i) { 103 for (uint32_t i = 0; i < length; ++i) {
95 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i)); 104 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i));
96 ASSERT(!item.IsEmpty()); 105 ASSERT(!item.IsEmpty());
97 if (V8ArrayBuffer::HasInstance(item, args.GetIsolate(), worldType(args.G etIsolate()))) { 106 if (V8ArrayBuffer::HasInstance(item, args.GetIsolate(), worldType(args.G etIsolate()))) {
98 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Ob ject>::Cast(item)); 107 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Ob ject>::Cast(item));
99 ASSERT(arrayBuffer); 108 ASSERT(arrayBuffer);
100 blobBuilder.append(arrayBuffer); 109 blobBuilder.append(arrayBuffer);
101 } else if (V8ArrayBufferView::HasInstance(item, args.GetIsolate(), world Type(args.GetIsolate()))) { 110 } else if (V8ArrayBufferView::HasInstance(item, args.GetIsolate(), world Type(args.GetIsolate()))) {
102 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::H andle<v8::Object>::Cast(item)); 111 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::H andle<v8::Object>::Cast(item));
103 ASSERT(arrayBufferView); 112 ASSERT(arrayBufferView);
104 blobBuilder.append(arrayBufferView); 113 blobBuilder.append(arrayBufferView);
105 } else 114 } else
106 if (V8Blob::HasInstance(item, args.GetIsolate(), worldType(args.GetIsola te()))) { 115 if (V8Blob::HasInstance(item, args.GetIsolate(), worldType(args.GetIsola te()))) {
107 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); 116 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item));
108 ASSERT(blob); 117 ASSERT(blob);
109 blobBuilder.append(blob); 118 blobBuilder.append(blob);
110 } else { 119 } else {
111 V8TRYCATCH(String, stringValue, toWebCoreString(item)); 120 V8TRYCATCH_VOID(String, stringValue, toWebCoreString(item));
112 blobBuilder.append(stringValue, endings); 121 blobBuilder.append(stringValue, endings);
113 } 122 }
114 } 123 }
115 124
116 RefPtr<Blob> blob = blobBuilder.getBlob(type); 125 RefPtr<Blob> blob = blobBuilder.getBlob(type);
117 return toV8(blob.get(), args.Holder(), args.GetIsolate()); 126 args.GetReturnValue().Set(toV8(blob.get(), args.Holder(), args.GetIsolate()) );
118 } 127 }
119 128
120 } // namespace WebCore 129 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698