Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should throw TypeError when assigning Document to doc.body. #97

Closed
StudentESE opened this issue Mar 28, 2017 · 2 comments
Closed

Should throw TypeError when assigning Document to doc.body. #97

StudentESE opened this issue Mar 28, 2017 · 2 comments

Comments

@StudentESE
Copy link

Hello,

I am using Koa2 ctx.body = doc which will fail with the error msg

TypeError: Converting circular structure to JSON

I used the example from your Readme:

var domino = require('domino');
var domimpl = domino.createDOMImplementation();
var doc = domimpl.createHTMLDocument();

Using a simple ctx.body="<html></html>" works fine.

I am using node v7.7.3 and Koa2.

Is this behavior known - and is it possible to work around this using Koa2 ?
(of cause: maybe I am using your work in a wrong way - please give me a hint 😄 )

Anyways: Thanks for publishing/sharing your work!

@cscott
Copy link
Collaborator

cscott commented Mar 28, 2017

Trying to set the body field to a Document is not going to work. When you try this in a brower's JavaScript console, you get:

> d = document.implementation.createHTMLDocument()
#document
> document.body = d
VM150:1 Uncaught TypeError: Failed to set the 'body' property on 'Document': The provided value is not of type 'HTMLElement'.
    at <anonymous>:1:15

Arguably domino should be more careful and throw a TypeError if you try this.

You probably want to be doing something involving adoptNode.

@cscott cscott changed the title TypeError: Converting circular structure to JSON Should throw TypeError when assigning Document to doc.body. Mar 28, 2017
@cscott
Copy link
Collaborator

cscott commented Aug 7, 2017

doc.body setter is already a nyi which will throw an exception:

$ node
> var domino = require('./');
undefined
>   var window = domino.createWindow();
undefined
> var doc = window.document;
undefined
> doc.body = 'foo'
Error: NotYetImplemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants