зеркало из https://github.com/microsoft/v8-jsi.git
Bump android jsi to 0.69-stable headers (#161)
* copy over jsi headers from rn/0.69-stable * fix unimplemented method
This commit is contained in:
Родитель
0803800621
Коммит
bf5e96b364
|
@ -309,6 +309,7 @@ namespace facebook { namespace v8runtime {
|
||||||
jsi::PropNameID createPropNameIDFromUtf8(const uint8_t* utf8, size_t length)
|
jsi::PropNameID createPropNameIDFromUtf8(const uint8_t* utf8, size_t length)
|
||||||
override;
|
override;
|
||||||
jsi::PropNameID createPropNameIDFromString(const jsi::String& str) override;
|
jsi::PropNameID createPropNameIDFromString(const jsi::String& str) override;
|
||||||
|
jsi::PropNameID createPropNameIDFromSymbol(const jsi::Symbol& sym) override;
|
||||||
std::string utf8(const jsi::PropNameID&) override;
|
std::string utf8(const jsi::PropNameID&) override;
|
||||||
bool compare(const jsi::PropNameID&, const jsi::PropNameID&) override;
|
bool compare(const jsi::PropNameID&, const jsi::PropNameID&) override;
|
||||||
|
|
||||||
|
|
|
@ -417,6 +417,10 @@ namespace facebook { namespace v8runtime {
|
||||||
return createPropNameID(stringRef(str));
|
return createPropNameID(stringRef(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jsi::PropNameID V8Runtime::createPropNameIDFromSymbol(const jsi::Symbol& sym) {
|
||||||
|
throw jsi::JSINativeException("V8Runtime::createPropNameIDFromSymbol is not implemented!");
|
||||||
|
}
|
||||||
|
|
||||||
std::string V8Runtime::utf8(const jsi::PropNameID& sym) {
|
std::string V8Runtime::utf8(const jsi::PropNameID& sym) {
|
||||||
_ISOLATE_CONTEXT_ENTER
|
_ISOLATE_CONTEXT_ENTER
|
||||||
return JSStringToSTLString(GetIsolate(), v8::Local<v8::String>::Cast(valueRef(sym)));
|
return JSStringToSTLString(GetIsolate(), v8::Local<v8::String>::Cast(valueRef(sym)));
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
V8_TAG="7.0.276.32"
|
V8_TAG="7.0.276.32"
|
||||||
RN_VERSION="0.68-stable"
|
RN_VERSION="0.69-stable"
|
||||||
NDK_VERSION="r21b"
|
NDK_VERSION="r21b"
|
||||||
NUGET_PKG_VERSION="0.68-stable-v1"
|
NUGET_PKG_VERSION="0.69-stable-v1"
|
|
@ -176,6 +176,9 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation {
|
||||||
PropNameID createPropNameIDFromString(const String& str) override {
|
PropNameID createPropNameIDFromString(const String& str) override {
|
||||||
return plain_.createPropNameIDFromString(str);
|
return plain_.createPropNameIDFromString(str);
|
||||||
};
|
};
|
||||||
|
PropNameID createPropNameIDFromSymbol(const Symbol& sym) override {
|
||||||
|
return plain_.createPropNameIDFromSymbol(sym);
|
||||||
|
};
|
||||||
std::string utf8(const PropNameID& id) override {
|
std::string utf8(const PropNameID& id) override {
|
||||||
return plain_.utf8(id);
|
return plain_.utf8(id);
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,6 +30,8 @@ std::string kindToString(const Value& v, Runtime* rt = nullptr) {
|
||||||
return "a number";
|
return "a number";
|
||||||
} else if (v.isString()) {
|
} else if (v.isString()) {
|
||||||
return "a string";
|
return "a string";
|
||||||
|
} else if (v.isSymbol()) {
|
||||||
|
return "a symbol";
|
||||||
} else {
|
} else {
|
||||||
assert(v.isObject() && "Expecting object.");
|
assert(v.isObject() && "Expecting object.");
|
||||||
return rt != nullptr && v.getObject(*rt).isFunction(*rt) ? "a function"
|
return rt != nullptr && v.getObject(*rt).isFunction(*rt) ? "a function"
|
||||||
|
@ -281,6 +283,15 @@ bool Value::strictEquals(Runtime& runtime, const Value& a, const Value& b) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Value::asBool() const {
|
||||||
|
if (!isBool()) {
|
||||||
|
throw JSINativeException(
|
||||||
|
"Value is " + kindToString(*this) + ", expected a boolean");
|
||||||
|
}
|
||||||
|
|
||||||
|
return getBool();
|
||||||
|
}
|
||||||
|
|
||||||
double Value::asNumber() const {
|
double Value::asNumber() const {
|
||||||
if (!isNumber()) {
|
if (!isNumber()) {
|
||||||
throw JSINativeException(
|
throw JSINativeException(
|
||||||
|
|
|
@ -274,6 +274,7 @@ class JSI_EXPORT Runtime {
|
||||||
const uint8_t* utf8,
|
const uint8_t* utf8,
|
||||||
size_t length) = 0;
|
size_t length) = 0;
|
||||||
virtual PropNameID createPropNameIDFromString(const String& str) = 0;
|
virtual PropNameID createPropNameIDFromString(const String& str) = 0;
|
||||||
|
virtual PropNameID createPropNameIDFromSymbol(const Symbol& sym) = 0;
|
||||||
virtual std::string utf8(const PropNameID&) = 0;
|
virtual std::string utf8(const PropNameID&) = 0;
|
||||||
virtual bool compare(const PropNameID&, const PropNameID&) = 0;
|
virtual bool compare(const PropNameID&, const PropNameID&) = 0;
|
||||||
|
|
||||||
|
@ -406,6 +407,7 @@ class JSI_EXPORT PropNameID : public Pointer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a PropNameID from utf8 values. The data is copied.
|
/// Create a PropNameID from utf8 values. The data is copied.
|
||||||
|
/// Results are undefined if \p utf8 contains invalid code points.
|
||||||
static PropNameID
|
static PropNameID
|
||||||
forUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) {
|
forUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) {
|
||||||
return runtime.createPropNameIDFromUtf8(utf8, length);
|
return runtime.createPropNameIDFromUtf8(utf8, length);
|
||||||
|
@ -413,6 +415,7 @@ class JSI_EXPORT PropNameID : public Pointer {
|
||||||
|
|
||||||
/// Create a PropNameID from utf8-encoded octets stored in a
|
/// Create a PropNameID from utf8-encoded octets stored in a
|
||||||
/// std::string. The string data is transformed and copied.
|
/// std::string. The string data is transformed and copied.
|
||||||
|
/// Results are undefined if \p utf8 contains invalid code points.
|
||||||
static PropNameID forUtf8(Runtime& runtime, const std::string& utf8) {
|
static PropNameID forUtf8(Runtime& runtime, const std::string& utf8) {
|
||||||
return runtime.createPropNameIDFromUtf8(
|
return runtime.createPropNameIDFromUtf8(
|
||||||
reinterpret_cast<const uint8_t*>(utf8.data()), utf8.size());
|
reinterpret_cast<const uint8_t*>(utf8.data()), utf8.size());
|
||||||
|
@ -423,6 +426,11 @@ class JSI_EXPORT PropNameID : public Pointer {
|
||||||
return runtime.createPropNameIDFromString(str);
|
return runtime.createPropNameIDFromString(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a PropNameID from a JS symbol.
|
||||||
|
static PropNameID forSymbol(Runtime& runtime, const jsi::Symbol& sym) {
|
||||||
|
return runtime.createPropNameIDFromSymbol(sym);
|
||||||
|
}
|
||||||
|
|
||||||
// Creates a vector of PropNameIDs constructed from given arguments.
|
// Creates a vector of PropNameIDs constructed from given arguments.
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
static std::vector<PropNameID> names(Runtime& runtime, Args&&... args);
|
static std::vector<PropNameID> names(Runtime& runtime, Args&&... args);
|
||||||
|
@ -502,14 +510,16 @@ class JSI_EXPORT String : public Pointer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a JS string from utf8-encoded octets. The string data is
|
/// Create a JS string from utf8-encoded octets. The string data is
|
||||||
/// transformed and copied.
|
/// transformed and copied. Results are undefined if \p utf8 contains invalid
|
||||||
|
/// code points.
|
||||||
static String
|
static String
|
||||||
createFromUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) {
|
createFromUtf8(Runtime& runtime, const uint8_t* utf8, size_t length) {
|
||||||
return runtime.createStringFromUtf8(utf8, length);
|
return runtime.createStringFromUtf8(utf8, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a JS string from utf8-encoded octets stored in a
|
/// Create a JS string from utf8-encoded octets stored in a
|
||||||
/// std::string. The string data is transformed and copied.
|
/// std::string. The string data is transformed and copied. Results are
|
||||||
|
/// undefined if \p utf8 contains invalid code points.
|
||||||
static String createFromUtf8(Runtime& runtime, const std::string& utf8) {
|
static String createFromUtf8(Runtime& runtime, const std::string& utf8) {
|
||||||
return runtime.createStringFromUtf8(
|
return runtime.createStringFromUtf8(
|
||||||
reinterpret_cast<const uint8_t*>(utf8.data()), utf8.length());
|
reinterpret_cast<const uint8_t*>(utf8.data()), utf8.length());
|
||||||
|
@ -966,9 +976,7 @@ class JSI_EXPORT Value {
|
||||||
std::is_base_of<String, T>::value ||
|
std::is_base_of<String, T>::value ||
|
||||||
std::is_base_of<Object, T>::value,
|
std::is_base_of<Object, T>::value,
|
||||||
"Value cannot be implicitly move-constructed from this type");
|
"Value cannot be implicitly move-constructed from this type");
|
||||||
#ifndef __clang_analyzer__ // TODO(macOS GH#774) Disable [bugprone-move-forwarding-reference] when running clang static analysis
|
|
||||||
new (&data_.pointer) T(std::move(other));
|
new (&data_.pointer) T(std::move(other));
|
||||||
#endif // __clang_analyzer__
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Value("foo") will treat foo as a bool. This makes doing that a
|
/// Value("foo") will treat foo as a bool. This makes doing that a
|
||||||
|
@ -984,7 +992,7 @@ class JSI_EXPORT Value {
|
||||||
|
|
||||||
/// Copies a Symbol lvalue into a new JS value.
|
/// Copies a Symbol lvalue into a new JS value.
|
||||||
Value(Runtime& runtime, const Symbol& sym) : Value(SymbolKind) {
|
Value(Runtime& runtime, const Symbol& sym) : Value(SymbolKind) {
|
||||||
new (&data_.pointer) String(runtime.cloneSymbol(sym.ptr_));
|
new (&data_.pointer) Symbol(runtime.cloneSymbol(sym.ptr_));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copies a String lvalue into a new JS value.
|
/// Copies a String lvalue into a new JS value.
|
||||||
|
@ -1070,6 +1078,10 @@ class JSI_EXPORT Value {
|
||||||
return data_.boolean;
|
return data_.boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \return the boolean value, or throws JSIException if not a
|
||||||
|
/// boolean.
|
||||||
|
bool asBool() const;
|
||||||
|
|
||||||
/// \return the number value, or asserts if not a number.
|
/// \return the number value, or asserts if not a number.
|
||||||
double getNumber() const {
|
double getNumber() const {
|
||||||
assert(isNumber());
|
assert(isNumber());
|
||||||
|
@ -1240,11 +1252,13 @@ class JSI_EXPORT JSIException : public std::exception {
|
||||||
JSIException(std::string what) : what_(std::move(what)){};
|
JSIException(std::string what) : what_(std::move(what)){};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
JSIException(const JSIException&) = default;
|
||||||
|
|
||||||
virtual const char* what() const noexcept override {
|
virtual const char* what() const noexcept override {
|
||||||
return what_.c_str();
|
return what_.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~JSIException();
|
virtual ~JSIException() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string what_;
|
std::string what_;
|
||||||
|
@ -1256,6 +1270,8 @@ class JSI_EXPORT JSINativeException : public JSIException {
|
||||||
public:
|
public:
|
||||||
JSINativeException(std::string what) : JSIException(std::move(what)) {}
|
JSINativeException(std::string what) : JSIException(std::move(what)) {}
|
||||||
|
|
||||||
|
JSINativeException(const JSINativeException&) = default;
|
||||||
|
|
||||||
virtual ~JSINativeException();
|
virtual ~JSINativeException();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1285,6 +1301,8 @@ class JSI_EXPORT JSError : public JSIException {
|
||||||
/// but necessary to avoid ambiguity with the above.
|
/// but necessary to avoid ambiguity with the above.
|
||||||
JSError(std::string what, Runtime& rt, Value&& value);
|
JSError(std::string what, Runtime& rt, Value&& value);
|
||||||
|
|
||||||
|
JSError(const JSError&) = default;
|
||||||
|
|
||||||
virtual ~JSError();
|
virtual ~JSError();
|
||||||
|
|
||||||
const std::string& getStack() const {
|
const std::string& getStack() const {
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace jsi {
|
||||||
class FileBuffer : public Buffer {
|
class FileBuffer : public Buffer {
|
||||||
public:
|
public:
|
||||||
FileBuffer(const std::string& path);
|
FileBuffer(const std::string& path);
|
||||||
~FileBuffer();
|
~FileBuffer() override;
|
||||||
|
|
||||||
size_t size() const override {
|
size_t size() const override {
|
||||||
return size_;
|
return size_;
|
||||||
|
|
|
@ -849,6 +849,8 @@ TEST_P(JSITest, ValueTest) {
|
||||||
EXPECT_EQ(eval("'str'").getString(rt).utf8(rt), "str");
|
EXPECT_EQ(eval("'str'").getString(rt).utf8(rt), "str");
|
||||||
EXPECT_TRUE(eval("[]").getObject(rt).isArray(rt));
|
EXPECT_TRUE(eval("[]").getObject(rt).isArray(rt));
|
||||||
|
|
||||||
|
EXPECT_TRUE(eval("true").asBool());
|
||||||
|
EXPECT_THROW(eval("123").asBool(), JSIException);
|
||||||
EXPECT_EQ(eval("456").asNumber(), 456);
|
EXPECT_EQ(eval("456").asNumber(), 456);
|
||||||
EXPECT_THROW(eval("'word'").asNumber(), JSIException);
|
EXPECT_THROW(eval("'word'").asNumber(), JSIException);
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
|
@ -1423,7 +1425,7 @@ TEST_P(JSITest, MultilevelDecoratedHostObject) {
|
||||||
EXPECT_EQ(1, RD2::numGets);
|
EXPECT_EQ(1, RD2::numGets);
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
Runtimes,
|
Runtimes,
|
||||||
JSITest,
|
JSITest,
|
||||||
::testing::ValuesIn(runtimeGenerators()));
|
::testing::ValuesIn(runtimeGenerators()));
|
||||||
|
|
Загрузка…
Ссылка в новой задаче