Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing tests for setting a TypedArray property with divergent receiver #3688

Open
gibson042 opened this issue Oct 14, 2022 · 1 comment
Open

Comments

@gibson042
Copy link
Contributor

https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-integer-indexed-exotic-objects-set-p-v-receiver requires an OrdinarySet when the property is a valid integer index and the Receiver argument does not match the associated typed array object, but there does not seem to be any test coverage and not all implementations get it right:

$ eshost -sx '
  var b = new Uint8Array(3);
  var spying = true;
  var p = new Proxy(
    {},
    Object.getOwnPropertyNames(Reflect)
      .map(name => [
        name,
        (...args) => {
          var result = Reflect[name](...args);
          var resultStr = typeof result === "object" ? JSON.stringify(result) : result;
          if (spying) {
            print(` ${name}(receiver, ${String(args[1])}, ...) => ${typeof result} ${resultStr}`);
          }
          return result;
        }
      ])
      .reduce(function assignFromEntry(obj, [key, val]){ obj[key] = val; return obj; }, {})
  );
  print(`set b[0] to 256 by assignment... ${b[0] = 256} => ${b[0]}\n`);
  print(`set b[1] to 257 by Reflect.set... ${Reflect.set(b, 1, 257)} => ${b[1]}\n`);
  print(`set b[2] to 258 by Reflect.set with receiver... ${Reflect.set(b, 2, 258, p)} => ${b[2]}\n`);
  spying = false;
  print("receiver own properties...");
  var entries = Object.entries(Object.getOwnPropertyDescriptors(p));
  for (var [key, desc] of entries) print(String(key), JSON.stringify(desc));
  if (!entries.length) print("<none>");
'
#### ChakraCore, GraalJS, Hermes, SpiderMonkey, V8
set b[0] to 256 by assignment... 256 => 0

set b[1] to 257 by Reflect.set... true => 1

 getOwnPropertyDescriptor(receiver, 2, ...) => undefined undefined
 defineProperty(receiver, 2, ...) => boolean true
set b[2] to 258 by Reflect.set with receiver... true => 0

receiver own properties...
2 {"value":258,"writable":true,"enumerable":true,"configurable":true}

#### engine262, JavaScriptCore, Moddable XS
set b[0] to 256 by assignment... 256 => 0

set b[1] to 257 by Reflect.set... true => 1

set b[2] to 258 by Reflect.set with receiver... true => 2

receiver own properties...
<none>
@gibson042
Copy link
Contributor Author

Related: #3444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant