Make window.ethereum.send writable

This commit is contained in:
Anthony Tseng
2022-08-30 09:53:18 -07:00
parent ff8151f7f2
commit d94a013944
2 changed files with 7 additions and 3 deletions
@@ -186,7 +186,7 @@ void JSEthereumProvider::CreateEthereumObject(
gin::StringToSymbol(isolate, kIsBraveWallet),
v8::True(isolate), v8::ReadOnly)
.Check();
// isMetaMask shuld be writable because of
// isMetaMask should be writable because of
// https://github.com/brave/brave-browser/issues/22213
ethereum_obj
->DefineOwnProperty(context, gin::StringToSymbol(isolate, "isMetaMask"),
@@ -198,8 +198,10 @@ void JSEthereumProvider::CreateEthereumObject(
.Check();
BindFunctionsToObject(isolate, context, ethereum_obj, metamask_obj);
UpdateAndBindJSProperties(isolate, context, ethereum_obj);
// send should be writable because of
// https://github.com/brave/brave-browser/issues/25078
for (const std::string& method :
{"request", "isConnected", "enable", "sendAsync", "send"}) {
{"request", "isConnected", "enable", "sendAsync"}) {
SetOwnPropertyNonWritable(context, ethereum_obj,
gin::StringToV8(isolate, method));
}
@@ -184,9 +184,11 @@ IN_PROC_BROWSER_TEST_F(JSEthereumProviderBrowserTest, NonWritable) {
EXPECT_EQ(base::Value(true), result.value) << result.error;
}
// window.ethereum.* (methods)
// send should be writable because of
// https://github.com/brave/brave-browser/issues/25078
for (const std::string& method :
{"on", "emit", "removeListener", "removeAllListeners", "request",
"isConnected", "enable", "sendAsync", "send"}) {
"isConnected", "enable", "sendAsync"}) {
SCOPED_TRACE(method);
auto result =
EvalJs(web_contents(), NonWriteableScriptMethod("ethereum", method),