Skip to content

goog.reflect.sinkValue and deadcode elimination #202

Description

@treblereel

One of the tips for preventing code removal by the compiler is the use of reflect.sinkValue from closure-library. Is it possible to use this feature without resorting to creating native.js?

lets say I have something like this:

public class Test {
    Random random = new Random();
    private void test() {
        DomGlobal.console.log("test "  + random.nextInt(10) + this.getClass().getCanonicalName());
    }
}

And I want to call it like this:

        Test test = new Test();
        ((Function)Js.asPropertyMap(test).get(objectProperty("m_test___$p_org_treblereel_Test", test))).bind(test).call();
         // it works for non inlined/removed functions       
    @JsMethod(namespace = "goog.reflect")
    public native static String objectProperty(String property, Object object);

What should I pass to sinkValue wrapper?

    @JsMethod(namespace = "goog.reflect")
    public native static Object sinkValue(??? value);

As I can see from the docs I should use something like sinkValue(test.m_test___$p_org_treblereel_Test) but it's not possible from java.

Activity

  1. locked and limited conversation to collaborators on Jul 25, 2023
  2. converted this issue into a discussion #203 on Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions