We went to RustConf last Saturday, and it was AWESOME.
Malisa is sick and focused on getting better
Things we did:
- Updating Headers
- A PR that Jeena opened a while ago finally got merged after fetch web platform test was updated.
- Promise in Fetch
- On Friday, wrapping
Rc<Promise>
withTrusted
didn’t work. Over the weekend Josh pushed another commit to enableTrusted<Promise>
andTrustedPromise::root()
that will return aRc<Promise>
. On Sunday, I encountered two borrow check errors:- process_response requires
&mut self
as a parameter (not mut self). When I try to get the root ofTrustedPromise
, it throws an error saying “cannot move out of borrowed content”. lines 122, 124, 136, and 138 - the
root()
ofTrustedPromise
requires self parameter. In line 101, withlet context = fetch_context.lock().unwrap();
which is typeMutexGuard
, which derefs to &T. When we try to access theRc<Promise>
viacontext.fetch_promise.root()
, the compiler throws a borrow error.
- process_response requires
- Today, I struggled a lot with the borrow checker, but now I have a compiling code! So I wrote a short html page that uses fetch to run it on Servo! (Based on MDN’s example)
- That helped me learn that Fetch isn’t working . I started debugging (which means, me = stressed out) and learned a few things:
-
metadata
that is used forprocess_response
looks good. It’sOk(_)
and has the fields that look not incorrect. - After promise is taken from FetchContext through
self.fetch_promise.take()
, no other line is called… WEIRD. WHY. Well, luckily, I was working at the Mozilla Office, and three(!) people helped me debug. Special thanks to @sanxiyn, @fitzgen, and @jimblandy.
-
- So, after using the debugger, this is what we learned:
- Here is the stack backtrace.
- Frame is older with higher frame number, i.e.
frame #6
is called beforeframe #5
. -
frame #6
shows thatto_jsval
was called. This in turn callsJS_WrapValue
inframe #5
. This in turn callsJSCompartment::wrap
inframe #4
. -
JSCompartment::wrap
is a C++ code in SpiderMonkey, a JavaScript engine.JSCompartment::wrap
has a parameter that isthis=&0x0
.0x0
is a null pointer!!! We have a memory-unsafety here!!! Woohoo!
- On Friday, wrapping
- Body
- Read the spec and some more about Unicode encodings in order to understand the UTF-8 decoder. Wrote a little code. Progress was slow due to being sick today.
Things we learned:
- When you write
.
after an object, it automatically derefs! For example, if I dofetch_context.lock()
, I’m derefingfetch_context
then applying thelock()
method. - assigning different types to the same binding name (via let statements) seems to be acceptable practice, at least in some contexts.
-
0x0
is the synonym to null pointer in C++! If your stack backtrace includes0x0
that’s probably not something you wanted :) - When debugging Servo, you can use the
--debug
tag, i.e../mach run -d ~/src/fetch_example.html --debug
. Servo uses lldb debugger by default. - You can set a breakpoint, for example, if you want the code to pause when it calls
rust_panic
function, you can writeb rust_panic
<ENTER>
run
. - While you’re at the breakpoint, (or maybe some other time too but I’m not too sure) you can type
bt
which will print all the backtrace! COOL. -
Rc
andTrusted
has to maintain a 1:1 relationship, and therefore,Trusted
should not have a&self
parameter because that could break that 1:1 constraint. In Servo’s promise,Rc
counts the references, and thereforeTrustedPromise
has to be connected to the one and onlyRc<Promise>
, because otherwise, the reference count will be incorrect.
TODO:
- Promise in Fetch
- Ask jdm about the null pointer!
- Body
- continue with UTF-8’s decoder