Make it possible for a Runtime to provide its own JSON parsing
Summary: Make it possible for a Runtime implementation to provide its own JSON parsing, by making the method on Value call through Runtime, which now has the default implementation. Reviewed By: tmikov Differential Revision: D17637395 fbshipit-source-id: b8997f7d1721a7790326417f3abfa86c875923c9
This commit is contained in:
Родитель
0a282c42b4
Коммит
9e7e178a2d
|
@ -102,6 +102,13 @@ Instrumentation& Runtime::instrumentation() {
|
|||
return sharedInstance;
|
||||
}
|
||||
|
||||
Value Runtime::createValueFromJsonUtf8(const uint8_t* json, size_t length) {
|
||||
Function parseJson = global()
|
||||
.getPropertyAsObject(*this, "JSON")
|
||||
.getPropertyAsFunction(*this, "parse");
|
||||
return parseJson.call(*this, String::createFromUtf8(*this, json, length));
|
||||
}
|
||||
|
||||
Pointer& Pointer::operator=(Pointer&& other) {
|
||||
if (ptr_) {
|
||||
ptr_->invalidate();
|
||||
|
@ -214,16 +221,6 @@ Value::~Value() {
|
|||
}
|
||||
}
|
||||
|
||||
Value Value::createFromJsonUtf8(
|
||||
Runtime& runtime,
|
||||
const uint8_t* json,
|
||||
size_t length) {
|
||||
Function parseJson = runtime.global()
|
||||
.getPropertyAsObject(runtime, "JSON")
|
||||
.getPropertyAsFunction(runtime, "parse");
|
||||
return parseJson.call(runtime, String::createFromUtf8(runtime, json, length));
|
||||
}
|
||||
|
||||
bool Value::strictEquals(Runtime& runtime, const Value& a, const Value& b) {
|
||||
if (a.kind_ != b.kind_) {
|
||||
return false;
|
||||
|
|
|
@ -252,6 +252,10 @@ class Runtime {
|
|||
virtual String createStringFromUtf8(const uint8_t* utf8, size_t length) = 0;
|
||||
virtual std::string utf8(const String&) = 0;
|
||||
|
||||
// \return a \c Value created from a utf8-encoded JSON string. The default
|
||||
// implementation creates a \c String and invokes JSON.parse.
|
||||
virtual Value createValueFromJsonUtf8(const uint8_t* json, size_t length);
|
||||
|
||||
virtual Object createObject() = 0;
|
||||
virtual Object createObject(std::shared_ptr<HostObject> ho) = 0;
|
||||
virtual std::shared_ptr<HostObject> getHostObject(const jsi::Object&) = 0;
|
||||
|
@ -974,7 +978,9 @@ class Value {
|
|||
|
||||
// \return a \c Value created from a utf8-encoded JSON string.
|
||||
static Value
|
||||
createFromJsonUtf8(Runtime& runtime, const uint8_t* json, size_t length);
|
||||
createFromJsonUtf8(Runtime& runtime, const uint8_t* json, size_t length) {
|
||||
return runtime.createValueFromJsonUtf8(json, length);
|
||||
}
|
||||
|
||||
/// \return according to the SameValue algorithm see more here:
|
||||
// https://www.ecma-international.org/ecma-262/5.1/#sec-11.9.4
|
||||
|
|
Загрузка…
Ссылка в новой задаче