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

caller is undefined,but it's not undefined in broswer. #1971

Closed
sgf opened this issue Sep 24, 2024 · 6 comments
Closed

caller is undefined,but it's not undefined in broswer. #1971

sgf opened this issue Sep 24, 2024 · 6 comments

Comments

@sgf
Copy link

sgf commented Sep 24, 2024

Version used

4.0.2

Describe the bug

caller is undefined,but it's not undefined in broswer.

To Reproduce

<script type="text/javascript">
  function Test(Lf_) {
      function h() {
          return getName();
      };
      return h();
      return 'Lf'
  };
  function getName() {
      debugger;
      var caller = getName.caller;
      if (caller.name) {
          return caller.name
      }
      var str = caller.toString().replace(/[\s]*/g, "");
      var name = str.match(/^function([^\(]+?)\(/);
      if (name && name[1]) {
          return name[1];
      } else {
          return '';
      }
  }
  Test();
</script>

Expected behavior

caller should be not undefined,in up code,its should be "h()";

Additional context

im using AngleSharp.Js.
AngleSharp/AngleSharp.Js#98

@sgf
Copy link
Author

sgf commented Sep 24, 2024

#819

Although this is not a standard definition feature. But I think Jint should be closer to the actual behavior of browsers while respecting the standard.
After all, in the end, we all aim for practicality.

@lahma
Copy link
Collaborator

lahma commented Sep 24, 2024

Would you like to propose a PR to implement this?

@sgf
Copy link
Author

sgf commented Sep 24, 2024

Would you like to propose a PR to implement this?

I don't mind propose an RP .

But I'm probably not good at this,due to I'm usually too lazy to write unit tests.

But as far as this function is concerned, there should be no side effects.

Engine.cs >FunctionDeclarationInstantiation

    function.SetProperty(KnownKeys.Caller, new PropertyDescriptor(this.GetExecutionContext(1).Function ?? ScriptFunction.Undefined, PropertyFlag.Configurable));

image

@lahma
Copy link
Collaborator

lahma commented Oct 12, 2024

Any updates?

@sgf
Copy link
Author

sgf commented Oct 18, 2024

I only added one line of code, and the local compilation was fine.
I looked at the logs, there were a lot of logs, but the most important failure was not obvious, I didn't even know where the error was.
Forget it, I gave up on making a PR.
I think it's too much effort. This is not my forte.

@sgf sgf closed this as completed Oct 18, 2024
@Genteure
Copy link
Contributor

The compilation is fine, yes. The problems are tests.

I know you said you give up, but the PR workflow failed because there are tests (https://github.com/tc39/test262) that check jint whether is actually spec compliant, meaning following the requirements of what is allowed and not allowed.

For example, according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller (note: MDN web docs is not the spec):

In strict mode, accessing caller of a function throws an error — the API is removed with no replacement.

That means you at the minimum needs to check if the current context is in strict mode before returning any value, and there are tests in test262 that check this.

You can not "fix" a behavior mismatch by creating another 100+ specification violations, that would only make the behavior of jint even further from browsers.

Have a nice day.

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

3 participants