Skip to content

ObjectInstance.ToString() raises an JavaScriptException #981

Answered by lahma
dmsch asked this question in Q&A
Discussion options

You must be logged in to vote

There problem here is that you create a plain ObjectInstance without a prototype chain. Prototype contains needed guidance how to handle common tasks, it also gives the JS functionality you are expected to find from any JS object. So two alternatives:

Use the way how engine constructs the final object (preferred):

using System;
using Jint;
using Jint.Runtime;

var engine = new Engine();

var instance = engine.Realm.Intrinsics.Object.Construct(Arguments.Empty);
Console.WriteLine(instance.ToString());

Or set prototype manually:

using System;
using Jint;
using Jint.Native.Object;

var engine = new Engine();

var instance = new ObjectInstance(engine);
instance.SetPrototypeOf(engine.Realm.Intr…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@lahma
Comment options

lahma Oct 20, 2021
Collaborator

@dmsch
Comment options

@lahma
Comment options

lahma Oct 20, 2021
Collaborator

@lahma
Comment options

lahma Oct 21, 2021
Collaborator

@dmsch
Comment options

Answer selected by dmsch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #980 on October 20, 2021 16:31.