Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions fixtures/html/htmlscriptelement-text.html
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to htmlscriptelement-text.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the test file from script-text-property-test.html to htmlscriptelement-text.html.

Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test HTMLScriptElement.text Getter/Setter</title>
<style>
body { font-family: sans-serif; }
.result-pass { color: green; }
.result-fail { color: red; }
.result { margin-bottom: 4px; }
pre { background: #f6f8fa; padding: 6px 10px; border-radius: 3px; }
</style>
</head>
<body>
<h2>Test <code>HTMLScriptElement.text</code> Getter/Setter</h2>
<div id="results"></div>
<pre id="details"></pre>
<script id="script1" type="text/javascript">
// Hello from script1
var x = 42;
</script>
<script>
function logResult(pass, message) {
const div = document.createElement('div');
div.className = 'result ' + (pass ? 'result-pass' : 'result-fail');
div.textContent = (pass ? "PASS: " : "FAIL: ") + message;
document.getElementById('results').appendChild(div);
console.log((pass ? "PASS: " : "FAIL: ") + message);
}
function appendDetails(text) {
document.getElementById('details').textContent += text + "\n";
}

const s1 = document.getElementById('script1');
appendDetails("Original .text: " + JSON.stringify(s1.text));
appendDetails("Original .textContent: " + JSON.stringify(s1.textContent));
logResult(
typeof s1.text === "string" && s1.text.includes('var x = 42;'),
"Getter: .text should contain script content"
);

s1.text = "// Replaced!\nlet y = 99;";
appendDetails("After set .text: " + JSON.stringify(s1.text));
logResult(
s1.text === "// Replaced!\nlet y = 99;",
"Setter: .text should replace script content"
);
logResult(
s1.textContent === s1.text,
".textContent should equal .text after set"
);

s1.text = "";
appendDetails("After set .text to empty: " + JSON.stringify(s1.text));
logResult(
s1.text === "",
"Setter: .text='' should clear script content"
);
logResult(
s1.childNodes.length === 0,
"Setter: .text='' should remove all child nodes"
);

s1.text = "console.log('test again');";
appendDetails("After set .text again: " + JSON.stringify(s1.text));
logResult(
s1.text === "console.log('test again');",
"Setter: .text can be set multiple times"
);

// Test multiple text nodes case
const scriptMulti = document.createElement('script');
const textNode1 = document.createTextNode('var a = 1;');
const textNode2 = document.createTextNode('var b = 2;');
const comment = document.createComment('this is a comment');

scriptMulti.appendChild(textNode1);
scriptMulti.appendChild(comment);
scriptMulti.appendChild(textNode2);

appendDetails("Multiple text nodes .text: " + JSON.stringify(scriptMulti.text));
logResult(
scriptMulti.text === 'var a = 1;var b = 2;',
"Getter: .text should concatenate multiple text nodes, ignoring comments"
);
appendDetails("Multiple text nodes .textContent: " + JSON.stringify(scriptMulti.textContent));
logResult(
scriptMulti.textContent === 'var a = 1;var b = 2;',
"Multiple text nodes: .textContent should equal .text"
);

// Test no text nodes case
const scriptEmpty = document.createElement('script');
const spanElement = document.createElement('span');
spanElement.textContent = 'nested content';
const commentOnly = document.createComment('only comment');

scriptEmpty.appendChild(spanElement);
scriptEmpty.appendChild(commentOnly);

appendDetails("No text nodes .text: " + JSON.stringify(scriptEmpty.text));
logResult(
scriptEmpty.text === '',
"Getter: .text should return empty string when no direct text children"
);
appendDetails("No text nodes .textContent: " + JSON.stringify(scriptEmpty.textContent));
logResult(
scriptEmpty.textContent === 'nested content',
"No text nodes: .textContent should include nested element content"
);
logResult(
scriptEmpty.text !== scriptEmpty.textContent,
"No text nodes: .text should differ from .textContent (spec compliance)"
);

// Test single text node fast path
const scriptSingle = document.createElement('script');
const singleTextNode = document.createTextNode('single text content');
scriptSingle.appendChild(singleTextNode);

appendDetails("Single text node .text: " + JSON.stringify(scriptSingle.text));
logResult(
scriptSingle.text === 'single text content',
"Getter: .text should handle single text node (fast path)"
);
logResult(
scriptSingle.text === scriptSingle.textContent,
"Single text node: .text should equal .textContent"
);
</script>
</body>
</html>
8 changes: 8 additions & 0 deletions src/client/html/html_script_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ namespace endor
src = value;
setAttribute("src", value);
}
inline void setText(const string &value)
{
setTextContent(value);
}
inline string getText() const
{
return textContent();
}

protected:
void createdCallback(bool from_scripting) override;
Expand Down
3 changes: 1 addition & 2 deletions src/client/script_bindings/events/all_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ namespace endor
DOM_EVENT_CLASSES_MAP(XX) \
XR_EVENT_CLASSES_MAP(XX)

void Initialize(Isolate *isolate)
{
void Initialize(Isolate *isolate){
#define XX(T) T::Initialize(isolate);
ALL_EVENT_CLASSES_MAP(XX)
#undef XX
Expand Down
4 changes: 2 additions & 2 deletions src/client/script_bindings/html/html_script_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ namespace endor
Isolate *isolate = info.GetIsolate();
HandleScope scope(isolate);
info.GetReturnValue().Set(String::NewFromUtf8(isolate,
handle()->text.c_str())
handle()->getText().c_str())
.ToLocalChecked());
}

Expand All @@ -176,7 +176,7 @@ namespace endor
}

String::Utf8Value text(isolate, value);
handle()->text = *text ? *text : "";
handle()->setText(*text ? *text : "");
}

void HTMLScriptElement::CharsetGetter(const PropertyCallbackInfo<Value> &info)
Expand Down
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/active_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ namespace endor
}

} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/active_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ namespace endor
};

} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ namespace endor
{
}
} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/framebuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ namespace endor
};

} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ namespace endor
// WebGLObject is a base class, typically not instantiated directly
}
} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ namespace endor
};

} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ namespace endor
}

} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/program.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ namespace endor
WebGLProgram(v8::Isolate *isolate, const v8::FunctionCallbackInfo<v8::Value> &args);
};
} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/renderbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ namespace endor
// WebGLRenderbuffer objects are created by WebGL context, not by user code
}
} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/renderbuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ namespace endor
};

} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ namespace endor
{
}
} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ namespace endor
};

} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/uniform_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ namespace endor
}

} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/uniform_location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ namespace endor
};

} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/vertex_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ namespace endor
{
}
} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor
2 changes: 1 addition & 1 deletion src/client/script_bindings/webgl/vertex_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ namespace endor
};

} // namespace webgl
} // namespace script_bindings
} // namespace script_bindings
} // namespace endor