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

change v8 typeof oporator to return 'object' instead of 'function' on host objects. #62

Closed
dirkelfman opened this issue Jul 31, 2018 · 2 comments
Assignees

Comments

@dirkelfman
Copy link

Is there a way to change typeof [HostObject] to return 'object' instead of 'function' .

        public class TestClass
        {
            public string Name { get; set; }
        }

        [TestMethod, TestCategory("V8ScriptEngine")]
        public void V8_typeof()
        {
            var testClass = new TestClass() { Name = "lisa" };
            engine.AddHostObject("testClass", testClass);
            Assert.AreEqual("object", (string)engine.Evaluate("typeof testClass"));
        }
@ClearScriptLib
Copy link
Collaborator

Hi @dirkelfman,

Unfortunately V8's typeof implementation returns "function" for all objects that are callable, which currently includes all host objects. We've discussed this with the V8 team here.

Many host objects are indeed callable, or potentially callable (delegates, host types, dynamic objects, "tear-off" methods, etc.), and will therefore always return "function". It might be possible to discern non-callable host objects and instantiate them through a dedicated non-callable template. We'll take a look.

Thanks!

@ClearScriptLib ClearScriptLib self-assigned this Jul 31, 2018
ClearScriptLib added a commit that referenced this issue Aug 20, 2018
…xed VB.NET access to nonexistent JavaScript properties (GitHub Issue #47, Take 2); fixed script object serialization via Json.NET (GitHub Issue #60); added host item invocability assessment and patched V8's typeof implementation to return "object" for all non-delegate host objects (GitHub Issue #62); added DocumentInfo and related APIs to address GitHub Issue #46; fixed property bag invocation; updated deployment and API documentation. Tested with V8 6.8.275.28.
@ClearScriptLib
Copy link
Collaborator

ClearScriptLib commented Aug 20, 2018

In Version 5.5.3, only delegates (and a few other special kinds of host objects) return "function" for typeof. The operator returns "object" for all other host objects.

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

No branches or pull requests

2 participants