File tree Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1577,6 +1577,11 @@ inline Object::PropertyLValue<Key>& Object::PropertyLValue<Key>::operator=(
15771577 return *this ;
15781578}
15791579
1580+ template <typename Key>
1581+ inline Value Object::PropertyLValue<Key>::AsValue () const {
1582+ return Value (*this );
1583+ }
1584+
15801585template <typename Key>
15811586inline Object::PropertyLValue<Key>::PropertyLValue (Object object, Key key)
15821587 : _env (object.Env ()), _object (object), _key (key) {}
Original file line number Diff line number Diff line change @@ -860,6 +860,9 @@ class Object : public TypeTaggable {
860860 template <typename ValueType>
861861 PropertyLValue& operator =(ValueType value);
862862
863+ // / Converts an L-value to a value. For convenience.
864+ Value AsValue () const ;
865+
863866 private:
864867 PropertyLValue () = delete ;
865868 PropertyLValue (Object object, Key key);
Original file line number Diff line number Diff line change @@ -128,6 +128,11 @@ static Value ToObject(const CallbackInfo& info) {
128128 return MaybeUnwrap (info[0 ].ToObject ());
129129}
130130
131+ static Value AccessProp (const CallbackInfo& info) {
132+ Object obj = MaybeUnwrap (info[0 ].ToObject ());
133+ return obj[info[1 ]].AsValue ();
134+ }
135+
131136Object InitBasicTypesValue (Env env) {
132137 Object exports = Object::New (env);
133138
@@ -150,6 +155,7 @@ Object InitBasicTypesValue(Env env) {
150155 exports[" toNumber" ] = Function::New (env, ToNumber);
151156 exports[" toString" ] = Function::New (env, ToString);
152157 exports[" toObject" ] = Function::New (env, ToObject);
158+ exports[" accessProp" ] = Function::New (env, AccessProp);
153159
154160 exports[" strictlyEquals" ] = Function::New (env, StrictlyEquals);
155161 exports[" strictlyEqualsOverload" ] = Function::New (env, StrictEqualsOverload);
Original file line number Diff line number Diff line change @@ -117,6 +117,21 @@ function test (binding) {
117117 assert ( value . assertNonEmptyReturnValOnCast ( ) ) ;
118118 }
119119
120+ function accessPropTest ( value ) {
121+ const testObject = { key : '123' } ;
122+ const testSymbol = Symbol ( '123' ) ;
123+ const testNumber = 123 ;
124+ const destObj = {
125+ testObject,
126+ testSymbol,
127+ [ testNumber ] : testNumber
128+ } ;
129+ assert . strictEqual ( value . accessProp ( destObj , 'testObject' ) , testObject ) ;
130+ assert . strictEqual ( value . accessProp ( destObj , 'testSymbol' ) , testSymbol ) ;
131+ assert . strictEqual ( value . accessProp ( destObj , testNumber ) , testNumber ) ;
132+ assert . strictEqual ( value . accessProp ( destObj , 'invalidKey' ) , undefined ) ;
133+ }
134+
120135 const value = binding . basic_types_value ;
121136
122137 assertValueStrictlyEqual ( value ) ;
@@ -153,4 +168,6 @@ function test (binding) {
153168 assert . strictEqual ( value . toString ( null ) , 'null' ) ;
154169
155170 typeConverterTest ( value . toObject , Object ) ;
171+
172+ accessPropTest ( value ) ;
156173}
You can’t perform that action at this time.
0 commit comments