6df2680cb6
* refactor: clean up webFrame implementation to use gin wrappers The previous implementation of webFrame in the renderer process leaked sub-frame contexts and global objects across the context boundaries thus making it possible for apps to either maliciously or accidentally violate the contextIsolation boundary. This re-implementation binds all methods in native code directly to content::RenderFrame instances instead of relying on JS to provide a "window" with every method request. This is much more consistent with the rest of the Electron codebase and is substantially safer. * chore: un-re-order for ease of review * chore: pass isolate around instead of ErrorThrower * chore: fix rebase typo * chore: remove unused variables
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
// Copyright (c) 2019 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/common/gin_helper/error_thrower.h"
|
|
|
|
#include "gin/converter.h"
|
|
|
|
namespace gin_helper {
|
|
|
|
ErrorThrower::ErrorThrower(v8::Isolate* isolate) : isolate_(isolate) {}
|
|
|
|
// This constructor should be rarely if ever used, since
|
|
// v8::Isolate::GetCurrent() uses atomic loads and is thus a bit
|
|
// costly to invoke
|
|
ErrorThrower::ErrorThrower() : isolate_(v8::Isolate::GetCurrent()) {}
|
|
|
|
ErrorThrower::~ErrorThrower() = default;
|
|
|
|
void ErrorThrower::ThrowError(base::StringPiece err_msg) const {
|
|
Throw(v8::Exception::Error, err_msg);
|
|
}
|
|
|
|
void ErrorThrower::ThrowTypeError(base::StringPiece err_msg) const {
|
|
Throw(v8::Exception::TypeError, err_msg);
|
|
}
|
|
|
|
void ErrorThrower::ThrowRangeError(base::StringPiece err_msg) const {
|
|
Throw(v8::Exception::RangeError, err_msg);
|
|
}
|
|
|
|
void ErrorThrower::ThrowReferenceError(base::StringPiece err_msg) const {
|
|
Throw(v8::Exception::ReferenceError, err_msg);
|
|
}
|
|
|
|
void ErrorThrower::ThrowSyntaxError(base::StringPiece err_msg) const {
|
|
Throw(v8::Exception::SyntaxError, err_msg);
|
|
}
|
|
|
|
void ErrorThrower::Throw(ErrorGenerator gen, base::StringPiece err_msg) const {
|
|
v8::Local<v8::Value> exception = gen(gin::StringToV8(isolate_, err_msg));
|
|
if (!isolate_->IsExecutionTerminating())
|
|
isolate_->ThrowException(exception);
|
|
}
|
|
|
|
} // namespace gin_helper
|