Skip to content

Commit

Permalink
bug: If property doesn't exist on object, don't throw KeyNotFoundExce…
Browse files Browse the repository at this point in the history
…ption

The spec says to check if the descriptor is undefined when calling
OrdinaryGet. Before this commit, we always tried to get the property
from the internal dictionary.

This would cause internal errors, throwing a KeyNotFoundException if the
property did not exist on the object.
  • Loading branch information
PrestonLTaylor committed Apr 17, 2024
1 parent cb0b444 commit 6a72279
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions JSS.Lib/AST/Values/Object.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,18 @@ internal Completion Get(string P, Object receiver)
// 10.1.8.1 OrdinaryGet ( O, P, Receiver ), https://tc39.es/ecma262/#sec-ordinaryget
static internal Completion OrdinaryGet(Object O, string P, Object receiver)
{
// FIXME: 1. Let desc be ? O.[[GetOwnProperty]](P).
// FIXME: 2. If desc is undefined, then
// FIXME: a. Let parent be ? O.[[GetPrototypeOf]]().
// FIXME: b. If parent is null, return undefined.
// FIXME: c. Return ? parent.[[Get]](P, Receiver).
// 1. Let desc be ? O.[[GetOwnProperty]](P).
var desc = O.GetOwnProperty(P);
if (desc.IsAbruptCompletion()) return desc;

// 2. If desc is undefined, then
if (desc.Value.IsUndefined())
{
// FIXME: a. Let parent be ? O.[[GetPrototypeOf]]().
// FIXME: b. If parent is null, return undefined.
// FIXME: c. Return ? parent.[[Get]](P, Receiver).
return Undefined.The;
}

// FIXME: 3. If IsDataDescriptor(desc) is true, return desc.[[Value]].
return O.DataProperties[P].Value;
Expand Down

0 comments on commit 6a72279

Please sign in to comment.