question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

xs throws GeneratorFunction.__proto__ was not Function.prototype.constructor

See original GitHub issue

Does this mean xs is non-conforming? Or just that it’s not a platform that this code knows about?

https://github.com/Agoric/harden/blob/0a5185ee224b98e75623a2f88143d118e0849eaa/src/anonIntrinsics.js#L230

for reference, my main.js:

import harden from '@agoric/harden';

export default function main() {
  trace("hi there\n");
  const h = harden({});
  trace("harded:", String(h), "\n");
}

and my manifest.json:

{
  "include": [
    "$(MODDABLE)/examples/manifest_base.json",
  ],
  "modules": {
    "*": [
      "./main",
    ],
    "@agoric/make-hardener": "./node_modules/@agoric/make-hardener/index",
    "@agoric/harden": "./node_modules/@agoric/harden/dist/harden.esm",
  },
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:25 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
phoddiecommented, Dec 29, 2019

We’ll post a change to the Moddable SDK in the coming days to address this. Meanwhile you can apply it locally by adding the following line…

slot->value.instance.prototype = mxFunctionConstructor.value.reference;

in xsGenerator.c after lines 72 and 97.

Patrick notes:

It is important that to understand the difference between executing code at link time and at run time. At link time, when vetted modules are preloaded, the prototype chains conform. Then the XS linker modify the prototype chains to prevent compartments to access constructors. So at runtime the prototype chains do not conform.

We have prepared an example Gist that shows the behavior.

At link time

_Function == Function true
_AsyncFunction.__proto__ == Function true
_AsyncGeneratorFunction.__proto__ == Function true
_GeneratorFunction.__proto__ == Function true

At runtime

_Function == Function false
_AsyncFunction.__proto__ == Function false
_AsyncGeneratorFunction.__proto__ == Function false
_GeneratorFunction.__proto__ == Function false

Maybe there are other invariants to test. And other bugs to fix. The example provides a way to experiment.

0reactions
jfparadiscommented, Feb 28, 2020

This issue has been resolved in SES 2.0, the code doing the collection of intrinsics assumed that it ran in JS, not in SES.

GeneratorFunction.__proto__ was not Function.prototype.constructor`

The check now works in both modes (JS and SES) because don’t check against Function, which can be tamed, but against Function.prototype.constructor which has a different value in SES and in JS.

Read more comments on GitHub >

github_iconTop Results From Across the Web

harden.esm.js - gists · GitHub
throw new Error('Generator.__proto__ was not Function.prototype');. } const GeneratorFunction = Generator.constructor;. const xs = true;. if (!xs) {.
Read more >
javascript - Why is it impossible to change constructor function ...
You cannot change a constructor by reassigning to prototype.constructor. What is happening is that Rabbit.prototype.constructor is a pointer to the original ...
Read more >
Inheritance and the prototype chain - JavaScript | MDN
Every instance created from a constructor function will automatically have the constructor's prototype property as its [[Prototype]] — that is, ...
Read more >
SES (Secure EcmaScript) details
The compartment constructor creates a new lightweight child realm with a new global , a new eval function, a new Function constructor, and...
Read more >
NodeJS - __proto__ & prototype Pollution - HackTricks
In Javascript, the concepts of the class and the function are quite ... The other way is to poison the prototype of a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found