Khan / Khan/live-editor

Prototype chains of incongruent prototypes corrupted by rewriteNewExpressions/PJSOutput.applyInstance

Open
#516 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
776
Forks
180
PR merge metrics
No merged PRs in 30d

Description

Disclaimer: I'm unfamiliar with the PJS testing infrastructure and also Processing.js.

As I see it, a stub class has been injected to enable annotation of injected code. The AST of NewExpressions are rewritten to insert the stub class, but makes the assumption that the returned object's prototype is congruent with the called class function. That prototype could be observed, but I think a simpler solution may be more robust. Annotation can be accomplished in a user-friendly way by using some form of non-enumerable properties.

I have a fork with some proposed changes at c7bfe6e82840f807a9c4f0a0aaa008fcbbba46bf
Note that four unit tests related PVector currently fail.

Here's a minimal example of the problem:

```
var X;
var Y = function() { return new X(); };
Y.prototype = {yProp: true};
X = function() {};
X.prototype = Object.assign(Object.create(Y.prototype), {xProp: true});
var a = new Y();
println(a instanceof X);
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Inspect rewriteNewExpressions and PJSOutput.applyInstance, then compare the proposed changes at commit c7bfe6e82840f807a9c4f0a0aaa008fcbbba46bf. Use the minimal prototype-chain example as a reproduction and run the PVector-related unit tests; done means prototype relationships remain correct and those tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.