Git Product home page Git Product logo

Comments (4)

paulbartrum avatar paulbartrum commented on July 30, 2024 1

ObjectInstance.Properties method marked as "internal"

Not sure why I changed this; I will make it public again.

There is no overload for JavaScriptException takes a innerException parameter without line number and file name.

Sure, I can add that.

ObjectInstance.GetMissingPropertyValue(object) virtual function is completely gone.

This functionality has been replaced by the ECMAScript 6 Proxy class. You can intercept property reads and writes and much more besides. :-)

JSON.stringify(input) throws error if input set to null instead of returning "null" string value

You should use Null.Value, which represents the JavaScript null value, instead of using null directly. Jurassic doesn't handle null consistently.

from jurassic.

lsim avatar lsim commented on July 30, 2024

If anyone else was wondering how to replace invocations to the now removed ObjectInstance.GetMissingPropertyValue(object) virtual function, an override of object GetPropertyValue(object key, object thisValue) seems to do the trick.

I was messing about trying to figure out how to use the new ES6 Proxy functionality for this, but I couldn't figure out how it relates to ObjectInstance.GetMissingPropertyValue(object) as suggested by Paul above.

from jurassic.

paulbartrum avatar paulbartrum commented on July 30, 2024

ES6 proxies allow you to wrap objects and use the wrapper to intercept operations. For example:

const target = {
    value: 'original value'
};

const handler = {
    get: function(target, prop, receiver) {
        if (prop === 'nonexistent') {
            return 'it exists now!';
        }
        // If the property name is not 'nonexistent' then return whatever property value is on the original object.
        return Reflect.get(target, prop, receiver);
    }
};

const proxy = new Proxy(target, handler);
console.log(proxy.value + ', ' + proxy.nonexistent);	// prints 'original value, it exists now!'

The proxy method should be more robust (less prone to change) then using GetPropertyValue(object, object) since it is part of the ECMAScript 6 standard, but realistically this project is in maintenance mode so it probably won't matter either way.

from jurassic.

lsim avatar lsim commented on July 30, 2024

Right.

One problem I was previously solving with ObjectInstance.GetMissingPropertyValue(object) was about transparently providing access to the properties of a C# object with hundreds of properties without proxying each property individually. Both to save typing and to remove the need for maintenance when new properties were added to the proxied object.

I suppose it would be possible to change our setup to have parts of the current .net api actually be JS proxies which rely on a new GetADynamicPropertyValue(string) method on the .net side. I think such a hybrid approach might complicate our API maintenance a bit though.

from jurassic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.