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

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

Issue 143313002: Implement URLSearchParams. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: More tests + ref count unattached URLSearchParams objects Created 6 years, 11 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014, Opera Software ASA. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of Opera Software ASA nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 * OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include "config.h"
31 #include "V8URLSearchParams.h"
32
33 #include "V8HTMLAnchorElement.h"
34 #include "V8URL.h"
35 #include "bindings/v8/ExceptionState.h"
36 #include "bindings/v8/V8Binding.h"
37 #include "bindings/v8/V8BindingMacros.h"
38 #include "bindings/v8/V8DOMWrapper.h"
39 #include "bindings/v8/V8GCController.h"
40 #include "bindings/v8/V8Utilities.h"
41 #include "core/dom/DOMURL.h"
42 #include "core/dom/DOMURLSearchParams.h"
43 #include "core/dom/DOMURLUtils.h"
44
45 namespace WebCore {
46
47 void V8URLSearchParams::constructorCustom(const v8::FunctionCallbackInfo<v8::Val ue>& info)
arv (Not doing code reviews) 2014/01/22 16:12:05 It is not clear to me why this needs a custom cons
sof 2014/01/22 17:15:47 Ah, it is possible to do without -- I overlooked s
48 {
49 ExceptionState exceptionState(ExceptionState::ConstructionContext, "URLSearc hParams", info.Holder(), info.GetIsolate());
50 if (!info.Length()) {
51 RefPtr<DOMURLSearchParams> searchParams = DOMURLSearchParams::create();
52 v8SetReturnValue(info, searchParams.release());
53 return;
54 }
55
56 v8::Handle<v8::Object> wrapper = info.Holder();
57 RefPtr<DOMURLSearchParams> searchParams;
58 if (V8URLSearchParams::hasInstance(info[0], info.GetIsolate(), worldType(inf o.GetIsolate()))) {
arv (Not doing code reviews) 2014/01/22 16:12:05 I thought hasInstance was updated. Did you sync re
59 V8TRYCATCH_EXCEPTION_VOID(DOMURLSearchParams*, initial, V8URLSearchParam s::toNative(v8::Handle<v8::Object>::Cast(info[0])), exceptionState);
60 searchParams = DOMURLSearchParams::create(initial);
61 } else if (info[0]->IsString()) {
62 searchParams = DOMURLSearchParams::create(toCoreString(info[0].As<v8::St ring>()));
63 } else {
64 exceptionState.throwTypeError("Argument not a string nor a URLSearchPara ms object.");
65 exceptionState.throwIfNeeded();
66 return;
67 }
68 V8DOMWrapper::associateObjectWithWrapper<V8URLSearchParams>(searchParams.rel ease(), &V8URLSearchParams::wrapperTypeInfo, wrapper, info.GetIsolate(), Wrapper Configuration::Dependent);
69 v8SetReturnValue(info, wrapper);
70 }
71
72 void V8URLSearchParams::visitDOMWrapper(void* object, const v8::Persistent<v8::O bject>& wrapper, v8::Isolate* isolate)
arv (Not doing code reviews) 2014/01/22 16:12:05 Could this be done with GenerateVisitDOMWrapper=ow
sof 2014/01/22 17:15:47 Definitely agree with that. The complexity enters
73 {
74 DOMURLSearchParams* impl = fromInternalPointer(object);
75 v8::Local<v8::Object> creationContext = v8::Local<v8::Object>::New(isolate, wrapper);
76 V8WrapperInstantiationScope scope(creationContext, isolate);
77 if (DOMURLUtils* urlObject = impl->urlObject()) {
78 switch (urlObject->implementedBy()) {
79 case DOMURLUtils::Anchor: {
80 HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(urlObjec t);
81 if (!DOMDataStore::containsWrapper<V8HTMLAnchorElement>(anchor, isol ate))
82 wrap(anchor, creationContext, isolate);
83 DOMDataStore::setWrapperReference<V8HTMLAnchorElement>(wrapper, anch or, isolate);
84 break;
85 }
86 case DOMURLUtils::DomURL: {
87 DOMURL* domURL = static_cast<DOMURL*>(urlObject);
88 if (!DOMDataStore::containsWrapper<V8URL>(domURL, isolate))
89 wrap(domURL, creationContext, isolate);
90 DOMDataStore::setWrapperReference<V8URL>(wrapper, domURL, isolate);
91 break;
92 }
93 default:
94 // Either an entirely unexpected condition or you've forgotten to
95 // extend this switch to include handling for a new type.
96 ASSERT_NOT_REACHED();
97 break;
98 }
99 }
100 setObjectGroup(object, wrapper, isolate);
101 }
102
103 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698