Skip to content

Commit 910bd74

Browse files
Jaroslav Tulachlkishalmi
authored andcommitted
Merging FixingProxies onto release100
1 parent aff7fb4 commit 910bd74

File tree

23 files changed

+433
-1085
lines changed

23 files changed

+433
-1085
lines changed

nbbuild/cluster.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ nb.cluster.platform=\
229229
libs.junit4,\
230230
libs.junit5,\
231231
libs.osgi,\
232-
libs.rhino,\
233232
libs.testng,\
234233
masterfs,\
235234
masterfs.linux,\

nbbuild/licenses/MPL-2.0

Lines changed: 0 additions & 373 deletions
This file was deleted.

platform/core.network/arch.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@
104104
which clients are supposed to download and execute in order to find
105105
out which proxy to use. This is known as <a href="https://en.wikipedia.org/wiki/Proxy_auto-config">Proxy Auto-Config</a>
106106
(or PAC). This module provides a pluggable PAC evaluation environment
107-
based on Rhino. Execution of the downloaded JavaScript code is sandboxed.
107+
based on Nashorn. However, it will gracefully degrade to any other JavaScript
108+
which may be installed in the JVM. Execution of the downloaded
109+
JavaScript code is sandboxed. (only true for Nashorn)
108110
</p>
109111
<p>
110112
If you don't like the PAC evaluation environment provided
@@ -730,6 +732,14 @@
730732
</question>
731733
-->
732734
<answer id="exec-reflection">
735+
<p>
736+
Yes. It detects the presence of Nashorn (as opposed to say Rhino) by way
737+
of reflection. In particular it needs to know if the Java version is
738+
Java 8u40 as Nashorn was greatly enhanced in that update and was more
739+
or less useless (for our purpose) before this time. The use of reflection
740+
means the code will gracefully 'degrade' to whatever script engine is
741+
available if we are not on Java 8u40 or later.
742+
</p>
733743
<p>
734744
For testing only a dirty hack is used in our <code>FakeDns</code> class.
735745
This installs itself as a preferred name service in Java. This is done

platform/core.network/nbproject/project.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@
6161
<specification-version>1.16</specification-version>
6262
</run-dependency>
6363
</dependency>
64-
<dependency>
65-
<code-name-base>org.netbeans.libs.rhino</code-name-base>
66-
<build-prerequisite/>
67-
<compile-dependency/>
68-
<run-dependency>
69-
<release-version>1</release-version>
70-
<specification-version>1.7.10</specification-version>
71-
</run-dependency>
72-
</dependency>
7364
<dependency>
7465
<code-name-base>org.netbeans.modules.keyring</code-name-base>
7566
<build-prerequisite/>

platform/core.network/src/org/netbeans/core/network/proxy/ProxyAutoConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.*;
2626
import java.util.logging.Level;
2727
import java.util.logging.Logger;
28+
import org.netbeans.core.NbLifecycleManager;
2829
import org.netbeans.core.network.proxy.pac.PacParsingException;
2930
import org.netbeans.core.network.proxy.pac.PacScriptEvaluator;
3031
import org.netbeans.core.network.proxy.pac.PacScriptEvaluatorFactory;
@@ -77,6 +78,7 @@ private ProxyAutoConfig(final String pacURL) throws URISyntaxException {
7778

7879
@Override
7980
public void run() {
81+
NbLifecycleManager.advancePolicy();
8082
initEngine();
8183
}
8284
});

platform/core.network/src/org/netbeans/core/network/proxy/pac/datetime/PacUtilsDateTime.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private static int getMonth(String month) throws PacDateTimeInputException {
260260

261261

262262
private static int getInteger(Object obj) throws PacDateTimeInputException {
263-
if (obj instanceof Number) {
263+
if (obj instanceof Integer || obj instanceof Long) {
264264
return ((Number) obj).intValue();
265265
}
266266
if (obj instanceof String) {
@@ -320,9 +320,8 @@ private static Calendar getCalendar(Date now, boolean useGMT) {
320320
* {@link PacHelperMethodsNetscape#weekdayRange(java.lang.Object...) weekdayRange()}
321321
*
322322
* <p>
323-
* Note: In Rhino, JavaScript function arguments that are not used in the
324-
* call will have a type of {@code java.lang.String} and the value will be
325-
* 'undefined'.
323+
* Note: In Nashorn, JavaScript function arguments that are not used in the
324+
* call will have a type of {@code Undefined}.
326325
*
327326
* @param objs
328327
* @return
@@ -338,8 +337,7 @@ public static int getNoOfParams(Object... objs) {
338337
}
339338
// Only parameters of type CharSequence (String) and
340339
// Number (Integer, Long, etc) are relevant.
341-
// Rhino converts javascript undefined to the string "undefined"
342-
if ((obj instanceof Number) || (obj instanceof CharSequence && (! "undefined".equals(obj)))) {
340+
if ((obj instanceof Number) || (obj instanceof CharSequence)) {
343341
params++;
344342
}
345343
}
@@ -353,9 +351,6 @@ public static int getNoOfParams(Object... objs) {
353351
*/
354352
public static boolean usesGMT(Object... args) {
355353
int params = getNoOfParams(args);
356-
if(params == 0) {
357-
return false;
358-
}
359354
if (args[params - 1] instanceof CharSequence) {
360355
String p = args[params - 1].toString();
361356
if (p.equals("GMT")) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.core.network.proxy.pac.impl;
20+
21+
import jdk.nashorn.api.scripting.ClassFilter;
22+
import org.netbeans.core.network.proxy.pac.PacHelperMethods;
23+
24+
/**
25+
* Nashorn class filter which helps us create a sandboxed JavaScript execution
26+
* environment which only has access to the Helper methods, nothing more.
27+
*
28+
* <p>Note that the ClassFilter feature is specific to Nashorn (Rhino had the
29+
* {@code ClassShutter} class for this purpose), but the feature did not appear
30+
* until Java 8u40.
31+
*
32+
* @author lbruun
33+
*/
34+
class ClassFilterPacHelpers implements ClassFilter {
35+
36+
@Override
37+
public boolean exposeToScripts(String string) {
38+
// The only Java class the PAC script is allowed to
39+
// make use of is the PAC Helpers, nothing more.
40+
return string.equals(PacHelperMethods.class.getName());
41+
}
42+
}

platform/core.network/src/org/netbeans/core/network/proxy/pac/impl/HelperScriptFactory.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,27 @@ private HelperScriptFactory() {
6363
/**
6464
* Gets JavaScript source with PAC Helper function declarations.
6565
*
66-
* @param bridgeObjectName name of Java object which contains Java methods,
67-
* named similarly to the JavaScript PAC helper functions and with
68-
* similar arg list. This Java object acts as the bridge between the
69-
* JavaScript world and the Java world and must be an instance
70-
* of {@link org.netbeans.network.proxy.pac.PacHelperMethods PacHelperMethods}.
71-
*
72-
* @return JavaScript source code
66+
* @return JavaScript source code that returns a function that delegates
67+
* to its first argument
7368
*/
74-
public static String getPacHelperSource(String bridgeObjectName) {
69+
public static String getPacHelperSource() {
7570
StringBuilder sb = new StringBuilder(2000);
76-
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_NS, bridgeObjectName);
77-
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_MS, bridgeObjectName);
78-
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_DEBUG, bridgeObjectName);
71+
sb.append("(function(self) {\n");
72+
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_NS);
73+
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_MS);
74+
addFunctionDecls(sb, JS_HELPER_FUNCTIONS_DEBUG);
75+
sb.append("})\n");
7976
return sb.toString();
8077
}
8178

8279

83-
private static void addFunctionDecls(StringBuilder sb, JsHelperFunction[] jsHelperFunctions, String bridgeObjectName) {
80+
private static void addFunctionDecls(StringBuilder sb, JsHelperFunction[] jsHelperFunctions) {
8481
for (JsHelperFunction f : jsHelperFunctions) {
85-
sb.append("function ");
82+
sb.append("this['");
8683
sb.append(f.functionName);
87-
sb.append('(');
84+
sb.append("'] = function(");
8885
addArgList(sb, f.argList);
89-
sb.append(") {");
90-
sb.append('\n');
86+
sb.append(") {\n");
9187
sb.append(" return ");
9288
boolean encloseReturnValue = false;
9389
if (Number.class.isAssignableFrom(f.getClass())) {
@@ -98,8 +94,7 @@ private static void addFunctionDecls(StringBuilder sb, JsHelperFunction[] jsHelp
9894
encloseReturnValue = true;
9995
sb.append("String(");
10096
}
101-
sb.append(bridgeObjectName);
102-
sb.append('.');
97+
sb.append("self.");
10398
sb.append(f.functionName);
10499
sb.append('(');
105100
addArgList(sb, f.argList);

0 commit comments

Comments
 (0)