mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(JSHandle.toString): clearer description for primitives (#993)
This patch: - updates JSHandle.toString to make a nicer description for primitives - excludes JSHandle.toString from documentation to avoid its abuse References #382
This commit is contained in:
parent
c3fb367148
commit
079db90066
@ -134,7 +134,6 @@
|
|||||||
+ [jsHandle.getProperties()](#jshandlegetproperties)
|
+ [jsHandle.getProperties()](#jshandlegetproperties)
|
||||||
+ [jsHandle.getProperty(propertyName)](#jshandlegetpropertypropertyname)
|
+ [jsHandle.getProperty(propertyName)](#jshandlegetpropertypropertyname)
|
||||||
+ [jsHandle.jsonValue()](#jshandlejsonvalue)
|
+ [jsHandle.jsonValue()](#jshandlejsonvalue)
|
||||||
+ [jsHandle.toString()](#jshandletostring)
|
|
||||||
* [class: ElementHandle](#class-elementhandle)
|
* [class: ElementHandle](#class-elementhandle)
|
||||||
+ [elementHandle.asElement()](#elementhandleaselement)
|
+ [elementHandle.asElement()](#elementhandleaselement)
|
||||||
+ [elementHandle.boundingBox()](#elementhandleboundingbox)
|
+ [elementHandle.boundingBox()](#elementhandleboundingbox)
|
||||||
@ -1509,9 +1508,6 @@ Returns a JSON representation of the object. The JSON is generated by running [`
|
|||||||
|
|
||||||
> **NOTE** The method will throw if the referenced object is not stringifiable.
|
> **NOTE** The method will throw if the referenced object is not stringifiable.
|
||||||
|
|
||||||
#### jsHandle.toString()
|
|
||||||
- returns: <[string]>
|
|
||||||
|
|
||||||
### class: ElementHandle
|
### class: ElementHandle
|
||||||
|
|
||||||
> **NOTE** Class [ElementHandle] extends [JSHandle].
|
> **NOTE** Class [ElementHandle] extends [JSHandle].
|
||||||
|
@ -184,7 +184,7 @@ class JSHandle {
|
|||||||
const type = this._remoteObject.subtype || this._remoteObject.type;
|
const type = this._remoteObject.subtype || this._remoteObject.type;
|
||||||
return 'JSHandle@' + type;
|
return 'JSHandle@' + type;
|
||||||
}
|
}
|
||||||
return helper.valueFromRemoteObject(this._remoteObject) + '';
|
return 'JSHandle:' + helper.valueFromRemoteObject(this._remoteObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
lib/Page.js
11
lib/Page.js
@ -330,8 +330,15 @@ class Page extends EventEmitter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const values = event.args.map(arg => this._frameManager.createJSHandle(event.executionContextId, arg));
|
const values = event.args.map(arg => this._frameManager.createJSHandle(event.executionContextId, arg));
|
||||||
const text = values.join(' ');
|
const textTokens = [];
|
||||||
const message = new ConsoleMessage(event.type, text, values);
|
for (let i = 0; i < event.args.length; ++i) {
|
||||||
|
const remoteObject = event.args[i];
|
||||||
|
if (remoteObject.objectId)
|
||||||
|
textTokens.push(values[i].toString());
|
||||||
|
else
|
||||||
|
textTokens.push(helper.valueFromRemoteObject(remoteObject));
|
||||||
|
}
|
||||||
|
const message = new ConsoleMessage(event.type, textTokens.join(' '), values);
|
||||||
this.emit(Page.Events.Console, message);
|
this.emit(Page.Events.Console, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,8 +408,10 @@ describe('Page', function() {
|
|||||||
|
|
||||||
describe('JSHandle.toString', function() {
|
describe('JSHandle.toString', function() {
|
||||||
it('should work for primitives', SX(async function() {
|
it('should work for primitives', SX(async function() {
|
||||||
const aHandle = await page.evaluateHandle(() => 2);
|
const numberHandle = await page.evaluateHandle(() => 2);
|
||||||
expect(aHandle.toString()).toBe('2');
|
expect(numberHandle.toString()).toBe('JSHandle:2');
|
||||||
|
const stringHandle = await page.evaluateHandle(() => 'a');
|
||||||
|
expect(stringHandle.toString()).toBe('JSHandle:a');
|
||||||
}));
|
}));
|
||||||
it('should work for complicated objects', SX(async function() {
|
it('should work for complicated objects', SX(async function() {
|
||||||
const aHandle = await page.evaluateHandle(() => window);
|
const aHandle = await page.evaluateHandle(() => window);
|
||||||
|
@ -37,6 +37,7 @@ const EXCLUDE_CLASSES = new Set([
|
|||||||
const EXCLUDE_METHODS = new Set([
|
const EXCLUDE_METHODS = new Set([
|
||||||
'Headers.fromPayload',
|
'Headers.fromPayload',
|
||||||
'Page.create',
|
'Page.create',
|
||||||
|
'JSHandle.toString',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user