Skip to content

Commit

Permalink
Improve handling of member expressions
Browse files Browse the repository at this point in the history
Summary:
In LRef differentiate between "by literal" and "by value" and handle the
latter more efficiently by simply remembering the property name.

Change the object value from an object pointer to a regular FNValue.

Use LRef in a couple of places instead of self.gen_prop(), which is now
unneeded and removed.

Add new object methods to FNObject: getByVal() and putByVal() taking
std::string for now.

Reviewed By: neildhar

Differential Revision: D37232324

fbshipit-source-id: e84868b60a3d729b25523129c491bb360a77c8c0
  • Loading branch information
tmikov authored and facebook-github-bot committed Jul 29, 2022
1 parent 00f26e5 commit c972e5e
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 98 deletions.
30 changes: 19 additions & 11 deletions unsupported/juno/crates/flow_native/runtime/FNRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@

const FNString fn_prototype_str{"prototype"};

FNValue FNObject::getByName(const std::string &key) {
auto *cur = this;
do {
auto it = cur->props.find(key);
if (it != cur->props.end())
return it->second;
cur = cur->parent;
} while (cur);
return FNValue::encodeUndefined();
}

void FNObject::putByName(const std::string &key, FNValue val) {
props[key] = val;
}

FNValue FNObject::getByVal(FNValue key) {
if (key.isString()) {
auto *cur = this;
do {
auto it = cur->props.find(key.getString()->str);
if (it != cur->props.end())
return it->second;
cur = cur->parent;
} while (cur);
return FNValue::encodeUndefined();
return getByName(key.getString()->str);
} else {
auto &arr = static_cast<FNArray *>(this)->arr;
double n = key.getNumber();
Expand All @@ -31,9 +39,9 @@ FNValue FNObject::getByVal(FNValue key) {
}

void FNObject::putByVal(FNValue key, FNValue val) {
if (key.isString())
props[key.getString()->str] = val;
else {
if (key.isString()) {
putByName(key.getString()->str, val);
} else {
auto &arr = static_cast<FNArray *>(this)->arr;
double n = key.getNumber();
if (arr.size() <= n)
Expand Down
2 changes: 2 additions & 0 deletions unsupported/juno/crates/flow_native/runtime/FNRuntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ struct FNObject {
std::unordered_map<std::string, FNValue> props;
FNObject *parent{};

FNValue getByName(const std::string &key);
void putByName(const std::string &key, FNValue val);
FNValue getByVal(FNValue key);
void putByVal(FNValue key, FNValue val);

Expand Down
Loading

0 comments on commit c972e5e

Please sign in to comment.