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

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentRequest.cpp

Issue 2463203002: Use JSON::Stringify instead of JSONValue (Closed)
Patch Set: Try to fix test failure Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/payments/PaymentRequest.h" 5 #include "modules/payments/PaymentRequest.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/JSONValuesForV8.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 8 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptState.h" 9 #include "bindings/core/v8/ScriptState.h"
10 #include "bindings/core/v8/V8StringResource.h"
11 #include "bindings/modules/v8/V8PaymentDetails.h" 11 #include "bindings/modules/v8/V8PaymentDetails.h"
12 #include "core/EventTypeNames.h" 12 #include "core/EventTypeNames.h"
13 #include "core/dom/DOMException.h" 13 #include "core/dom/DOMException.h"
14 #include "core/dom/ExceptionCode.h" 14 #include "core/dom/ExceptionCode.h"
15 #include "core/events/Event.h" 15 #include "core/events/Event.h"
16 #include "core/events/EventQueue.h" 16 #include "core/events/EventQueue.h"
17 #include "core/frame/FrameOwner.h" 17 #include "core/frame/FrameOwner.h"
18 #include "core/html/HTMLIFrameElement.h" 18 #include "core/html/HTMLIFrameElement.h"
19 #include "modules/EventTargetModulesNames.h" 19 #include "modules/EventTargetModulesNames.h"
20 #include "modules/payments/HTMLIFrameElementPayments.h" 20 #include "modules/payments/HTMLIFrameElementPayments.h"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 359
360 for (const auto& pmd : paymentMethodData) { 360 for (const auto& pmd : paymentMethodData) {
361 if (pmd.supportedMethods().isEmpty()) { 361 if (pmd.supportedMethods().isEmpty()) {
362 exceptionState.throwTypeError( 362 exceptionState.throwTypeError(
363 "Must specify at least one payment method identifier"); 363 "Must specify at least one payment method identifier");
364 return; 364 return;
365 } 365 }
366 366
367 String stringifiedData = ""; 367 String stringifiedData = "";
368 if (pmd.hasData() && !pmd.data().isEmpty()) { 368 if (pmd.hasData() && !pmd.data().isEmpty()) {
369 std::unique_ptr<JSONValue> value = 369 if (!pmd.data().v8Value()->IsObject() ||
370 toJSONValue(pmd.data().context(), pmd.data().v8Value()); 370 pmd.data().v8Value()->IsArray()) {
371 if (!value) { 371 exceptionState.throwTypeError(
372 "Data should be a JSON-serializable object");
373 return;
374 }
375
376 v8::MaybeLocal<v8::String> value = v8::JSON::Stringify(
377 pmd.data().context(), pmd.data().v8Value().As<v8::Object>());
378 if (value.IsEmpty()) {
haraken 2016/11/02 01:19:01 v8::Local<v8::String> value; if (!v8::JSON::String
372 exceptionState.throwTypeError( 379 exceptionState.throwTypeError(
373 "Unable to parse payment method specific data"); 380 "Unable to parse payment method specific data");
374 return; 381 return;
375 } 382 }
376 if (!value->isNull()) { 383 stringifiedData = v8StringToWebCoreString<String>(value.ToLocalChecked(),
377 if (value->getType() != JSONValue::TypeObject) { 384 DoNotExternalize);
378 exceptionState.throwTypeError(
379 "Data should be a JSON-serializable object");
380 return;
381 }
382 stringifiedData = JSONObject::cast(value.get())->toJSONString();
383 }
384 } 385 }
385 methodData->append( 386 methodData->append(
386 PaymentRequest::MethodData(pmd.supportedMethods(), stringifiedData)); 387 PaymentRequest::MethodData(pmd.supportedMethods(), stringifiedData));
387 } 388 }
388 } 389 }
389 390
390 String getSelectedShippingOption(const PaymentDetails& details) { 391 String getSelectedShippingOption(const PaymentDetails& details) {
391 String result; 392 String result;
392 if (!details.hasShippingOptions()) 393 if (!details.hasShippingOptions())
393 return result; 394 return result;
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 m_completeTimer.stop(); 852 m_completeTimer.stop();
852 m_completeResolver.clear(); 853 m_completeResolver.clear();
853 m_showResolver.clear(); 854 m_showResolver.clear();
854 m_abortResolver.clear(); 855 m_abortResolver.clear();
855 if (m_clientBinding.is_bound()) 856 if (m_clientBinding.is_bound())
856 m_clientBinding.Close(); 857 m_clientBinding.Close();
857 m_paymentProvider.reset(); 858 m_paymentProvider.reset();
858 } 859 }
859 860
860 } // namespace blink 861 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698