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

Unified Diff: third_party/WebKit/Source/modules/nfc/NFC.cpp

Issue 2473533002: Make NFC.cpp use JSON::Stringify (Closed)
Patch Set: Fix logic error 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/nfc/NFC.cpp
diff --git a/third_party/WebKit/Source/modules/nfc/NFC.cpp b/third_party/WebKit/Source/modules/nfc/NFC.cpp
index a8e470f1096f4ea3cd4a30c2d5821a160c7de889..408cd9e62f5a6f4e7514ee21cdddbee3cea3cc53 100644
--- a/third_party/WebKit/Source/modules/nfc/NFC.cpp
+++ b/third_party/WebKit/Source/modules/nfc/NFC.cpp
@@ -7,6 +7,7 @@
#include "bindings/core/v8/JSONValuesForV8.h"
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/V8ArrayBuffer.h"
+#include "bindings/core/v8/V8StringResource.h"
#include "core/dom/DOMArrayBuffer.h"
#include "core/dom/DOMException.h"
#include "core/dom/Document.h"
@@ -173,11 +174,14 @@ struct TypeConverter<mojo::WTFArray<uint8_t>, blink::ScriptValue> {
return mojo::WTFArray<uint8_t>::From<WTF::String>(stringResource);
}
- if (value->IsObject() && !value->IsArrayBuffer()) {
- std::unique_ptr<blink::JSONValue> jsonResult =
- blink::toJSONValue(scriptValue.context(), value);
- if (jsonResult && (jsonResult->getType() == blink::JSONValue::TypeObject))
- return mojo::WTFArray<uint8_t>::From(jsonResult->toJSONString());
+ if (value->IsObject() && !value->IsArray() && !value->IsArrayBuffer()) {
+ v8::Local<v8::String> jsonString;
+ if (v8::JSON::Stringify(scriptValue.context(), value.As<v8::Object>())
+ .ToLocal(&jsonString)) {
+ WTF::String wtfString = blink::v8StringToWebCoreString<WTF::String>(
+ jsonString, blink::DoNotExternalize);
+ return mojo::WTFArray<uint8_t>::From(wtfString);
+ }
}
if (value->IsArrayBuffer())

Powered by Google App Engine
This is Rietveld 408576698