Skip to content

Commit 9010bfe

Browse files
neildharfacebook-github-bot
authored andcommitted
Add PropNameID::fromSymbol
Summary: Changelog: [General][Added] - Add ability to access properties with symbol keys through JSI Reviewed By: mhorowitz Differential Revision: D33830544 fbshipit-source-id: 8de366b4c7d5ea9d2fd5df70dfb776a056e23806
1 parent 3c4850d commit 9010bfe

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

ReactCommon/jsi/JSCRuntime.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class JSCRuntime : public jsi::Runtime {
151151
jsi::PropNameID createPropNameIDFromUtf8(const uint8_t *utf8, size_t length)
152152
override;
153153
jsi::PropNameID createPropNameIDFromString(const jsi::String &str) override;
154+
jsi::PropNameID createPropNameIDFromSymbol(const jsi::Symbol &sym) override;
154155
std::string utf8(const jsi::PropNameID &) override;
155156
bool compare(const jsi::PropNameID &, const jsi::PropNameID &) override;
156157

@@ -653,6 +654,13 @@ jsi::PropNameID JSCRuntime::createPropNameIDFromString(const jsi::String &str) {
653654
return createPropNameID(stringRef(str));
654655
}
655656

657+
jsi::PropNameID JSCRuntime::createPropNameIDFromSymbol(const jsi::Symbol &sym) {
658+
// TODO: Support for symbols through the native API in JSC is very limited.
659+
// While we could construct a PropNameID here, we would not be able to get a
660+
// symbol property through the C++ API.
661+
throw std::logic_error("Not implemented");
662+
}
663+
656664
std::string JSCRuntime::utf8(const jsi::PropNameID &sym) {
657665
return JSStringToSTLString(stringRef(sym));
658666
}

ReactCommon/jsi/jsi/decorator.h

+3
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ class RuntimeDecorator : public Base, private jsi::Instrumentation {
176176
PropNameID createPropNameIDFromString(const String& str) override {
177177
return plain_.createPropNameIDFromString(str);
178178
};
179+
PropNameID createPropNameIDFromSymbol(const Symbol& sym) override {
180+
return plain_.createPropNameIDFromSymbol(sym);
181+
};
179182
std::string utf8(const PropNameID& id) override {
180183
return plain_.utf8(id);
181184
};

ReactCommon/jsi/jsi/jsi.h

+6
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ class JSI_EXPORT Runtime {
274274
const uint8_t* utf8,
275275
size_t length) = 0;
276276
virtual PropNameID createPropNameIDFromString(const String& str) = 0;
277+
virtual PropNameID createPropNameIDFromSymbol(const Symbol& sym) = 0;
277278
virtual std::string utf8(const PropNameID&) = 0;
278279
virtual bool compare(const PropNameID&, const PropNameID&) = 0;
279280

@@ -425,6 +426,11 @@ class JSI_EXPORT PropNameID : public Pointer {
425426
return runtime.createPropNameIDFromString(str);
426427
}
427428

429+
/// Create a PropNameID from a JS symbol.
430+
static PropNameID forSymbol(Runtime& runtime, const jsi::Symbol& sym) {
431+
return runtime.createPropNameIDFromSymbol(sym);
432+
}
433+
428434
// Creates a vector of PropNameIDs constructed from given arguments.
429435
template <typename... Args>
430436
static std::vector<PropNameID> names(Runtime& runtime, Args&&... args);

0 commit comments

Comments
 (0)