From 2cbde0a9766cee8ed7c8684d9196612aef0a89c1 Mon Sep 17 00:00:00 2001 From: AlexCD Date: Mon, 30 Aug 2021 23:00:00 +0300 Subject: [PATCH] prevent uninitialized js objects --- .../htmlunit/javascript/SimpleScriptable.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptable.java b/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptable.java index 7eaf43b67f3..667565f49bc 100644 --- a/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptable.java +++ b/src/main/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptable.java @@ -78,6 +78,18 @@ public Object get(String name, final Scriptable start) { // Try to get property configured on object itself. Object response = super.get(name, start); if (response != NOT_FOUND) { + if (response instanceof ScriptableObject) { + ScriptableObject responseScriptable = (ScriptableObject) response; + if (responseScriptable.getParentScope() == null) { + responseScriptable.setParentScope(this.getParentScope()); + } + } + if (response instanceof SimpleScriptable) { + SimpleScriptable simpleScriptable = (SimpleScriptable) response; + if (simpleScriptable.getPrototype() == null) { + simpleScriptable.setPrototype(getPrototype(simpleScriptable.getClass())); + } + } return response; } if (this == start) {