1842 case "call": 1843 return findCallMethod(desc, request); 1844 case "new": 1845 return findNewMethod(desc, request); 1846 case "callMethod": 1847 return findCallMethodMethod(desc, request); 1848 default: 1849 return null; 1850 } 1851 } 1852 1853 /** 1854 * Find the appropriate New method for an invoke dynamic call. 1855 * 1856 * @param desc The invoke dynamic call site descriptor. 1857 * @param request The link request 1858 * 1859 * @return GuardedInvocation to be invoked at call site. 1860 */ 1861 protected GuardedInvocation findNewMethod(final CallSiteDescriptor desc, final LinkRequest request) { 1862 return notAFunction(); 1863 } 1864 1865 /** 1866 * Find the appropriate CALL method for an invoke dynamic call. 1867 * This generates "not a function" always 1868 * 1869 * @param desc the call site descriptor. 1870 * @param request the link request 1871 * 1872 * @return GuardedInvocation to be invoked at call site. 1873 */ 1874 protected GuardedInvocation findCallMethod(final CallSiteDescriptor desc, final LinkRequest request) { 1875 return notAFunction(); 1876 } 1877 1878 private GuardedInvocation notAFunction() { 1879 throw typeError("not.a.function", ScriptRuntime.safeToString(this)); 1880 } 1881 1882 /** 1883 * Find an implementation for a "dyn:callMethod" operation. Note that Nashorn internally never uses 1884 * "dyn:callMethod", but instead always emits two call sites in bytecode, one for "dyn:getMethod", and then another 1885 * one for "dyn:call". Explicit support for "dyn:callMethod" is provided for the benefit of potential external 1886 * callers. The implementation itself actually folds a "dyn:getMethod" method handle into a "dyn:call" method handle. 1887 * 1888 * @param desc the call site descriptor. 1889 * @param request the link request 1890 * 1891 * @return GuardedInvocation to be invoked at call site. 1892 */ 1893 protected GuardedInvocation findCallMethodMethod(final CallSiteDescriptor desc, final LinkRequest request) { 1894 // R(P0, P1, ...) 1895 final MethodType callType = desc.getMethodType(); 1896 // use type Object(P0) for the getter 1897 final CallSiteDescriptor getterType = desc.changeMethodType(MethodType.methodType(Object.class, callType.parameterType(0))); 1898 final GuardedInvocation getter = findGetMethod(getterType, request, "getMethod"); 1899 | 1842 case "call": 1843 return findCallMethod(desc, request); 1844 case "new": 1845 return findNewMethod(desc, request); 1846 case "callMethod": 1847 return findCallMethodMethod(desc, request); 1848 default: 1849 return null; 1850 } 1851 } 1852 1853 /** 1854 * Find the appropriate New method for an invoke dynamic call. 1855 * 1856 * @param desc The invoke dynamic call site descriptor. 1857 * @param request The link request 1858 * 1859 * @return GuardedInvocation to be invoked at call site. 1860 */ 1861 protected GuardedInvocation findNewMethod(final CallSiteDescriptor desc, final LinkRequest request) { 1862 return notAFunction(desc); 1863 } 1864 1865 /** 1866 * Find the appropriate CALL method for an invoke dynamic call. 1867 * This generates "not a function" always 1868 * 1869 * @param desc the call site descriptor. 1870 * @param request the link request 1871 * 1872 * @return GuardedInvocation to be invoked at call site. 1873 */ 1874 protected GuardedInvocation findCallMethod(final CallSiteDescriptor desc, final LinkRequest request) { 1875 return notAFunction(desc); 1876 } 1877 1878 private GuardedInvocation notAFunction(final CallSiteDescriptor desc) { 1879 throw typeError("not.a.function", NashornCallSiteDescriptor.getFunctionErrorMessage(desc, this)); 1880 } 1881 1882 /** 1883 * Find an implementation for a "dyn:callMethod" operation. Note that Nashorn internally never uses 1884 * "dyn:callMethod", but instead always emits two call sites in bytecode, one for "dyn:getMethod", and then another 1885 * one for "dyn:call". Explicit support for "dyn:callMethod" is provided for the benefit of potential external 1886 * callers. The implementation itself actually folds a "dyn:getMethod" method handle into a "dyn:call" method handle. 1887 * 1888 * @param desc the call site descriptor. 1889 * @param request the link request 1890 * 1891 * @return GuardedInvocation to be invoked at call site. 1892 */ 1893 protected GuardedInvocation findCallMethodMethod(final CallSiteDescriptor desc, final LinkRequest request) { 1894 // R(P0, P1, ...) 1895 final MethodType callType = desc.getMethodType(); 1896 // use type Object(P0) for the getter 1897 final CallSiteDescriptor getterType = desc.changeMethodType(MethodType.methodType(Object.class, callType.parameterType(0))); 1898 final GuardedInvocation getter = findGetMethod(getterType, request, "getMethod"); 1899 |