OLD | NEW |
---|---|
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 "platform/JSONValuesForV8.h" | 5 #include "bindings/core/v8/JSONValuesForV8.h" |
6 | |
7 #include "bindings/core/v8/ExceptionState.h" | |
8 #include "bindings/core/v8/V8Binding.h" | |
6 | 9 |
7 namespace blink { | 10 namespace blink { |
8 | 11 |
9 static String coreString(v8::Local<v8::String> v8String) | 12 static String coreString(v8::Local<v8::String> v8String) |
10 { | 13 { |
11 int length = v8String->Length(); | 14 int length = v8String->Length(); |
12 UChar* buffer; | 15 UChar* buffer; |
13 String result = String::createUninitialized(length, buffer); | 16 String result = String::createUninitialized(length, buffer); |
14 v8String->Write(reinterpret_cast<uint16_t*>(buffer), 0, length); | 17 v8String->Write(reinterpret_cast<uint16_t*>(buffer), 0, length); |
15 return result; | 18 return result; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 if (!propertyValue) | 79 if (!propertyValue) |
77 return nullptr; | 80 return nullptr; |
78 jsonObject->setValue(coreString(propertyName), propertyValue); | 81 jsonObject->setValue(coreString(propertyName), propertyValue); |
79 } | 82 } |
80 return jsonObject; | 83 return jsonObject; |
81 } | 84 } |
82 ASSERT_NOT_REACHED(); | 85 ASSERT_NOT_REACHED(); |
83 return nullptr; | 86 return nullptr; |
84 } | 87 } |
85 | 88 |
89 v8::Local<v8::Value> fromJSONString(v8::Local<v8::Context> context, const String & stringifiedJSON, ExceptionState& exceptionState) | |
haraken
2016/03/02 00:46:16
Nit: You can pass in ScriptState rather than v8::C
please use gerrit instead
2016/03/02 01:24:34
Done.
| |
90 { | |
91 v8::Isolate* isolate = context->GetIsolate(); | |
92 v8::Local<v8::Value> parsed; | |
93 v8::TryCatch tryCatch(isolate); | |
haraken
2016/03/02 00:46:16
Use scriptState->isolate().
please use gerrit instead
2016/03/02 01:24:34
Done.
| |
94 if (!v8Call(v8::JSON::Parse(isolate, v8String(isolate, stringifiedJSON)), pa rsed, tryCatch)) { | |
95 if (tryCatch.HasCaught()) | |
96 exceptionState.rethrowV8Exception(tryCatch.Exception()); | |
haraken
2016/03/02 00:46:16
Have you confirmed that this throws an exception a
please use gerrit instead
2016/03/02 01:24:34
For PaymentResponse, the stringified JSON comes fr
| |
97 } | |
98 | |
99 return parsed; | |
100 } | |
101 | |
86 } // namespace blink | 102 } // namespace blink |
OLD | NEW |