Add spec for destroying synchronous event.
This commit is contained in:
parent
65176761f4
commit
5480cf58c2
4 changed files with 33 additions and 3 deletions
|
@ -23,7 +23,7 @@ Event::Event()
|
||||||
}
|
}
|
||||||
|
|
||||||
Event::~Event() {
|
Event::~Event() {
|
||||||
if (sender_)
|
if (sender_ != NULL)
|
||||||
sender_->RemoveObserver(this);
|
sender_->RemoveObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ v8::Handle<v8::Object> Event::CreateV8Object() {
|
||||||
|
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "preventDefault", PreventDefault);
|
NODE_SET_PROTOTYPE_METHOD(t, "preventDefault", PreventDefault);
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "sendReply", SendReply);
|
NODE_SET_PROTOTYPE_METHOD(t, "sendReply", SendReply);
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(t, "destroy", Destroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Handle<v8::Object> v8_event =
|
v8::Handle<v8::Object> v8_event =
|
||||||
|
@ -87,8 +88,8 @@ v8::Handle<v8::Value> Event::SendReply(const v8::Arguments& args) {
|
||||||
if (event == NULL)
|
if (event == NULL)
|
||||||
return node::ThrowError("Event is already destroyed");
|
return node::ThrowError("Event is already destroyed");
|
||||||
|
|
||||||
if (event->message_ == NULL)
|
if (event->message_ == NULL || event->sender_ == NULL)
|
||||||
return node::ThrowError("Can only send reply to synchronous events once");
|
return node::ThrowError("Can only send reply to synchronous events");
|
||||||
|
|
||||||
string16 json = FromV8Value(args[0]);
|
string16 json = FromV8Value(args[0]);
|
||||||
|
|
||||||
|
@ -99,6 +100,12 @@ v8::Handle<v8::Value> Event::SendReply(const v8::Arguments& args) {
|
||||||
return v8::Undefined();
|
return v8::Undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
v8::Handle<v8::Value> Event::Destroy(const v8::Arguments& args) {
|
||||||
|
delete Unwrap<Event>(args.This());
|
||||||
|
return v8::Undefined();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -49,6 +49,7 @@ class Event : public node::ObjectWrap,
|
||||||
|
|
||||||
static v8::Handle<v8::Value> PreventDefault(const v8::Arguments& args);
|
static v8::Handle<v8::Value> PreventDefault(const v8::Arguments& args);
|
||||||
static v8::Handle<v8::Value> SendReply(const v8::Arguments& args);
|
static v8::Handle<v8::Value> SendReply(const v8::Arguments& args);
|
||||||
|
static v8::Handle<v8::Value> Destroy(const v8::Arguments& args);
|
||||||
|
|
||||||
static v8::Persistent<v8::FunctionTemplate> constructor_template_;
|
static v8::Persistent<v8::FunctionTemplate> constructor_template_;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@ assert = require 'assert'
|
||||||
ipc = require 'ipc'
|
ipc = require 'ipc'
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
remote = require 'remote'
|
remote = require 'remote'
|
||||||
|
BrowserWindow = remote.require 'browser-window'
|
||||||
|
|
||||||
|
fixtures = path.resolve __dirname, '..', 'fixtures'
|
||||||
|
|
||||||
describe 'ipc', ->
|
describe 'ipc', ->
|
||||||
fixtures = path.join __dirname, '..', 'fixtures'
|
fixtures = path.join __dirname, '..', 'fixtures'
|
||||||
|
@ -58,3 +61,13 @@ describe 'ipc', ->
|
||||||
it 'can be replied by setting event.returnValue', ->
|
it 'can be replied by setting event.returnValue', ->
|
||||||
msg = ipc.sendChannelSync 'echo', 'test'
|
msg = ipc.sendChannelSync 'echo', 'test'
|
||||||
assert.equal msg, 'test'
|
assert.equal msg, 'test'
|
||||||
|
|
||||||
|
it 'does not crash when reply is not sent and both browser and event are destroyed', (done) ->
|
||||||
|
w = new BrowserWindow(show: false)
|
||||||
|
remote.require('ipc').once 'send-sync-message', (event) ->
|
||||||
|
event.returnValue = null
|
||||||
|
|
||||||
|
w.destroy()
|
||||||
|
event.destroy()
|
||||||
|
done()
|
||||||
|
w.loadUrl 'file://' + path.join(fixtures, 'api', 'send-sync-message.html')
|
||||||
|
|
9
spec/fixtures/api/send-sync-message.html
vendored
Normal file
9
spec/fixtures/api/send-sync-message.html
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
var ipc = require('ipc');
|
||||||
|
ipc.sendChannelSync('send-sync-message', 'message');
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue